重构-改善既有的代码设计-重新组织数据(8-2)

版权声明:不自见故明;不自是故彰;不自伐故有功;不自矜故长; https://blog.csdn.net/LightUpHeaven/article/details/84656895

8.7.将单向关联改为双向关联(Change Unidirectional Association to Bidirectional)

8.8.将双向关联改为单向关联(Change Bidirectional Association to Unidirectional)

8.9.以字面常量取代魔法数(Replace Magic Number with Symbolic Constant)

8.10.封装字段(Encapsulate Field)

8.11.封装集合(Encapsulate Collection)

普通的情况,愈少出现。

8.12.以数据类取代记录(Replace Record with Data Class)

8.13.以类取代类型码(Replace Type Code with Class)

这条规则主要是为了确保TypeCode的有效性,不用检测传入的BloodGroup是否有效。因为只会传BloodGroup.A,B这种已创建好的。

8.14.以子类取代类型码(Replace Type Code with SubSubclasses)

8.15.以State/Strategy取代类型码(Replace Type Code with State/Strategy)

8.16.以字段取代子类(Replace Subclass with Fields)

猜你喜欢

转载自blog.csdn.net/LightUpHeaven/article/details/84656895