聊聊軟體開發的REP、CCP、CRP原則

codecraft發表於2022-04-12

本文主要研究一下軟體開發的REP、CCP、CRP原則

The Reuse/Release Equivalence Principle (REP)

複用/釋出等同原則
The granular of reuse is the granular of release.
軟體複用的最小粒度應等同於其釋出的最小粒度,需要有自己的釋出版本號。

The Common Closure Principle (CCP)

共同閉包原則,即元件層面的單一職責原則
The classes in a component should be closed together against the same kinds of changes. A change that affects a component affects all the classes in that component and no other components.
我們應該將那些會同時修改,並且為相同目的而修改的類放到同一個元件中,而將不會同時修改,並且不會為了相同目的而修改的那些類放到不同的元件中。

對大部分應用程式來說,可維護性的重要性要遠遠高於可複用性。如果某程式中的程式碼必須要進行某些變更,那麼這些變更最好都體現在同一個元件中,而不是分佈於很多個元件中。因為如果這些變更都集中在同一個元件中,我們就只需要重新部署該元件,其他元件則不需要被重新驗證、重新部署了

The Common Reuse Principle (CRP)

共同複用原則
The classes in a component are reused together. If you reuse one of the classes in a component, you reuse them all.
不要強迫一個元件的使用者依賴他們不需要的東西。建議我們將經常共同複用的類和模組放在同一個元件中。

小結

REP和CCP原則是黏合性原則,它們會讓元件變得更大,而CRP原則是排除性原則,它會盡量讓元件變小。

doc

相關文章