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