`
biqing0427
  • 浏览: 57280 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

对象内转移特性(Moving Features Between Objects)

OOP 
阅读更多

1.Move Method

  • 有个函数与其所驻CLASS之外的另一个CLASS进行更多交流,调用后者,或被后者调用。
  • 如果SOME CLASS 的 SUBCLASS和SUPERCLASS出现其他声明,无法进行搬移,除非TARGET CLASS也同样表现出多态性
  • 将SOURCE METHOD使之成为一个DELEGATING METHOD
  • 需要使用SOURCE CLASS特性,四种选择:
    • 将这个特性也移到TARGET CLASS
    • 建立或使用一个从TARGET CLASS到SOURCE的引用关系
    • 将SOURCE OBJECT当作参数传给TARGET METHOD
    • 如果所需特性是个变量,将它当作参数传给TARGET METHOD

2.Move Fied

  • 某个FIED被其所驻CLASS之外的另一个CLASS更多的使用
  • 用SELF-ENCAPSULATION对SOURCE CLASS的FIED的进行封装
  • 值域移到其他函数,需要考虑相关的引用也要一起移动

3. Extract Class

  •  建立一个新CLASS,将相关的值域和函数从旧CLASS搬移到新CLASS.
  •  一个有用的测试:如果你搬移了某些值域或函数,会发生什么事?其他值域和函数是否因此变得无意义?
  •  是改善并发程序的一种常用技术,因为它使你可以为提炼后的两个CLASS分别加锁。
  •  这种方法常见与CLASS的分离,功能特性的提炼,使功能更单一,细粒度增加

4. Inline Class

  • 将CLASS的所有特性搬移到另一个CLASS中,然后移除原CLASS。
  • 功能的合并,便于处理,去掉不必要的细粒度。

5. Hide Delegate

  • 在SERVER端放置一个简单的委托函数,将委托关系隐藏起来,从而去除这种依存性。

6. Remove Middle Man

  • 与Hide Delegate 相反

7. Introduce Foreign Method

  • 在CLIENT CLASS中建立一个函数,并以一个SERVER CLASS 实体作为第一引数。
  • 在CLIENT端增加额外的功能,这种情况用于增加功能少,与SERVER端对象性关联性小。

8. Introduce Local Extension

  • OOP中的扩展性的应用
  • 建立一个新CLASS,使它包含这些额外函数,让这个扩展品成为SOURCE CLASS的SUBCLASS或者WRAPPER
  • 首选SUBCLASS,SUBCLASSING迫使必须产生一个SUBCLASS对象,这种情况下如果有其他对象引用了旧对象,我们就同时有了两个对象保存了原数据。如果原数据是不可修改的,那也没问题。但如果原数据是允许被修改的,一个修改动作无法同时改变两个拷贝,这时候必须改用WRAPPER。

 

 

 

分享到:
评论

相关推荐

    重构_改善既有代码的设计

    第 7 章:在对象之间移动特性(Moving Features Between Objects) 第 8 章:重新组织你的数据(Organizing Data) 第 9 章:简化条件表达式(Simplifying Conditional Expressions) 第 10 章:简化函数...

    重构 改善既有代码的设计

    Chapter 7:Moving Features Between Objects 在对象之间移动特性  *Move Method 移动方法   Move Field 移动字段   Extract Class 提取类   Inline Class 内联类   Hide Delegate 隐藏委托类   ...

    Refactoring

    The heart of the book is a catalog of refactorings, organized in chapters on composing methods, moving features between objects, organizing data, simplifying conditional expressions, and dealing with...

    重构-改善既有代码的设计+中文版

    Chapter 7:Moving Features Between Objects 在对象之间移动特性  *Move Method 移动方法   Move Field 移动字段   Extract Class 提取类   Inline Class 内联类   Hide Delegate 隐藏委托类   Remove ...

    重构——改善既有代码的设计

    Chapter 7:Moving Features Between Objects 在对象之间移动特性  *Move Method 移动方法   Move Field 移动字段   Extract Class 提取类   Inline Class 内联类   Hide Delegate 隐藏委托类   Remove ...

    重构-改善既有代码的设计(中文版)

    Chapter 7:Moving Features Between Objects 在对象之间移动特性  *Move Method 移动方法   Move Field 移动字段   Extract Class 提取类   Inline Class 内联类   Hide Delegate 隐藏委托类   Remove ...

    重构,改善既有代码的设计

    Chapter 7:Moving Features Between Objects 在对象之间移动特性  *Move Method 移动方法   Move Field 移动字段   Extract Class 提取类   Inline Class 内联类   Hide Delegate 隐藏委托类   ...

    Effective Modern C++ 原版pdf by Meyers

    Moving objects is normally better than copying them. There’s a lot to learn about C++11, not to mention C++14. More importantly, there’s a lot to learn about making effective use of the new ...

    Active Directory Cookbook, 3rd Edition.pdf

    Covers all aspects of managing user objects, including creating, renaming, moving, resetting passwords, unlocking, modifying the profile attributes, and locating users that have certain criteria (e.g....

    Object Tracking

    Online Learning and Robust Visual Tracking using Local Features and Global Appearances of Video Objects Chapter 6 Switching Local and Covariance Matching for Efficient Object Tracking Chapter 7 ...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - FIX: With little difference between curve angles at smaller scales the curve was drawn backwards (error in TFlexEllipse.Paint). - ADD: Support of the binary document format. Added the public ...

    salesforce dev 501 Notes

    The Force.com Migration Tool is a powerful utility for moving metadata between local directories and Salesforce environments. It supports files such as: - **Apex Classes**: Code files that define ...

    Professional C# 3rd Edition

    Communication between Contexts 462 Remote Objects, Clients, and Servers 462 Remote Objects 462 A Simple Server 464 A Simple Client 465 .NET Remoting Architecture 466 Channels 466 Formatters 470 ...

    Cours-VB-NET-2010-Developpez-com

    The course follows a structured approach, starting with fundamental concepts and gradually moving towards more complex topics. The sequence ensures that learners build a solid foundation before ...

    Unreal Engine 4.X By Example

    This project involves creating a character that can hop between barrels in a level. - **Creating Our Character**: Designing a character actor and adding necessary components. - **Bringing Our ...

    Python程序设计(第二版).chm

    The Compulsory Features List Section 1.4. What's Python Good For? Section 1.5. What's Python Not Good For? Part I: System Interfaces Chapter 2. System Tools Section 2.1. "The os.path to ...

Global site tag (gtag.js) - Google Analytics