Android活动命名 [英] Android activity naming

查看:88
本文介绍了Android活动命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android活动和其他类之间遇到越来越多的命名冲突.我想知道您是否可以告诉我如何避免这些情况.遗憾的是,我的特定命名问题并未包含在SO的相关问题中.

I'm running into more and more naming clashes between Android activities and other classes. I was wondering if you could tell me how you avoid these. Sadly, my particular naming problems are not covered in the related questions on SO.

第一个示例

我有一个显示游戏水平的活动.但是,该级别所需的数据(背景图稿,实体等)存储在单独的类中.自然,我将后者称为Level.但是,我也将活动称为Level,因为它显示级别.

I have an activity that displays a level of the game. However, the data required for that level (background artwork, entities etc.) is stored in a separate class. Naturally, I would call the latter class Level. However, I would call the activity Level as well, because it displays levels.

第二个示例

我有一个回放剪辑场景的活动.它基本上连续显示几张图像.所显示的图像信息持续存储在一个单独的类中.和前面的情况一样,我自然会把这两个类都称为CutScene.

I have an activity that plays back a cut scene. It basically displays several images in a row. The information which image is shown for how long is stored in a separate class. As in the previous case, I would naturally call both classes CutScene.

您将如何解决这些命名问题?将活动命名为LevelActivityCutSceneActivity?将表示形式类命名为LevelModelCutSceneModel?还有吗?

How would you solve these naming issues? Name the activities LevelActivity and CutSceneActivity? Name the representation classes LevelModel and CutSceneModel? Something else?

推荐答案

我通过为类添加类型"作为前缀或后缀来解决这些问题,就像您在问题末尾所建议的那样:

I solve those problems by either prefixing or postfixing classes with their "type", like you suggested at the end of your question :

  • LevelActivityGameActivityMainActivity,...
  • CommentsListAdapter,...
  • CheckNewCommentsService,...
  • 以此类推.
  • LevelActivity, GameActivity, MainActivity, ...
  • CommentsListAdapter, ...
  • CheckNewCommentsService, ...
  • and so on.

但是我通常对包含这些数据的对象的模型类执行一个操作:我仍将我的Level模型类命名为Level,而不是LevelModel,以表示我正在操作并正常工作加上一个关卡.

But I generally do an execption for the model classes, which are the objects that contain that data : I would still name my Level model class Level, and not LevelModel, to indicate I'm manipulating, and working with, a Level.


另一个解决方案(长时间键入^^)可能是使用完全限定的名称​​(请参见


Another solution (longer to type ^^) might be to use fully-qualified names (see here) when referencing your classes :

  • com.something.yourapp.activity.Level
  • com.something.yourapp.model.Level
  • com.something.yourapp.activity.Level
  • com.something.yourapp.model.Level

有了这个,您总是知道真正使用哪个类.

With this, you always know which class is really used.

这篇关于Android活动命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆