Android activity naming

后端 未结 2 1644
抹茶落季
抹茶落季 2021-02-04 02:50

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 namin

2条回答
  •  醉梦人生
    2021-02-04 02:57

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

    • LevelActivity, GameActivity, MainActivity, ...
    • CommentsListAdapter, ...
    • CheckNewCommentsService, ...
    • and so on.

    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

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

提交回复
热议问题