friend依賴性刪除重構
Unveiling the Need for Refactoring
Consider the following scenario: ClassA and ClassAAccessor share a friend dependency, granting ClassAAccessor access to protected members of ClassA.雖然這看起來很方便,但它帶來了幾個缺點:UML 2.2已將朋友刻板印象置換為刻板印象。
Refactoring Step-by-Step
Step 2: Move Operations to the Interface
Identify the operations constituting the call dependency and move them from ClassA to InternalInterface, extending InternalInterface with a protected constructor and marking ClassA's generalization association to InternalInterface as protected.Step 3: Connect the組件
ClassaAccessor需要對InternalInterface的引用。在classa中實現附加方法,即actactAccessor(),並使用setInternalInternInterFaceref()將其引用到ClastaAccessor。當調用Classa :: actacta :: actactaAccessor()。 班級classaaccessor { 民眾: ClassaAccessor(Classa&Classa); void setInternalInterfaceRef(內部接口和newValue); 私人的: 內部接口* internalterfaceref; }; //將引用引用到Internalterface的方法 classa :: actactaccessor(ClassaAccessor&Conscontor){ consector.setInternal Interfaceref(*this); }免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3