C++ Primer 4/e在Constructors and Copy Control这个地方有一个关键概念:‘Adding Disc_item to the Item_base hierarchy is an example of refactoring. Refactoring involves redesigning a class hierarchy to move operations and/or data from one class to another. Refactoring happens most often when classes are redesigned to add new functionality or handle other changes in that application’s requirements.
Refactoring is common in OO applications. It is noteworthy that even though we changed the inheritance hierarchy, code that uses the Bulk_item or Item_base classes would not need to change. However, when classes are refactored, or changed in any other way, any code that uses those classes must be recompiled.’
中文版的这样写:‘为Item_base继承体系加入Disc_item,正可用来演练重构程序,其中涉及重新设计class继承体系、将class的操作或资料移至另一个class。重构最常发生于“重新设计classes以加入新功能”或“处理应用程式所需的其他改变”之时。
重构常见于OO程式。值得一提的是,即使我们改变了继承体系,Bulk_item或Item_base的应用程式码不需要更动。当然啦如果classes被重构或以其它方式改变,其用户程式码必须重新编译。’
我想生活中常常会碰到这一类的例子,特别设计一开始考虑的并不周延,或为了因应新产生的经济活动时,特别会牵涉到重构的设计功能。