类设计技巧 Class Design Hints

    技术2022-05-11  74

    1    Always keep data private.2    Always initialize data.3    Don't use too many basic types in a class.4    Not all fields need individual field accessors and mutators.      You may need to get and set an employee's salary. You certainly won't need to change the hiring date once the object is constructed. And, quite often, objects have instance fields that you don't want others to get or set, for example, an array of state abbreviations in an Address class.5    Use a standard form for class definitions.6    Break up classes with too many responsibilities.7    Make the names of your classes and methods reflect their responsibilities.

    最新回复(0)