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.
转载请注明原文地址: https://ibbs.8miu.com/read-16966.html