Refactoring

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被重構或以其它方式改變,其用戶程式碼必須重新編譯。』

我想生活中常常會碰到這一類的例子,特別設計一開始考慮的並不週延,或為了因應新產生的經濟活動時,特別會牽涉到重構的設計功能。

感謝你看到這裡,很快就可以離開了,但最好的獎勵行動就是按一下幫我分享或留言,感恩喔~

點我分享到Facebook

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *