Classes(2)

Constructors
1. Initialize all member data in all constructors, if possible.
2. Initialize data members in the order in which they're declared.
3. Enfore the singleton property by using a a private constructor(It seems like the Singleton pattern in GoF)
4. Enforce the singleton property by using all static member data and reference counting.
5. Prefer deep copies to shallow copies until proven otherwise.
A deep copy of an object is a member-wise copy of the object's member data. A shallow copy typically just points to or refer to a single reference copy.

Reason to Create a Class
1. Model real-world objects
2. Model abstract objects--an object that isn't a concrete, real-world object, but that privides an abstraction of other concrete objects. A good example is the classic Shape object.
3. Reduce complexity. 
Create a class to hide information so that you won't need to think about it.
4. Isolate complexity.
5. Hide implementation details.
6. Limit effects of chagnes.
Isolate areas that are likely to chagne so that the effects of changes are limited to the scope of a sinlge or, at most a few classes.
7. Hide global data.
8. Streamline parameter passing.
If you're passing a parameter among several routines, that might indicate a need to factor those routines into a class that share the parameter as class data.
9. Make central points of control.
It's a good idea to control each task in one place.
10. Facilitate reusable code.
11. Plan for a family of programs.
Seems just like the item 6.
12. Package related operations.
In case in which you can't hide information, share data, or plan for flexibility, you can still package sets of operations into sensible groups such as statistcal functions, string-manipulation routines and so on.
13. To accomplish a specific refactoring.

Classes to Avoid
1. Avoid creating god classes.
2. Eliminate irrelevant classes.
If a class consists only of data but no behavior, ask yourself whether it's really a class.
3. Avoid classes named after verbs.
A class that only behavior but no data is generally not really a class.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值