`
biqing0427
  • 浏览: 55724 次
  • 性别: 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 隐藏委托类   ...

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

    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 隐藏委托类   ...

    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 ...

    A Practical Introduction to Computer Vision with OpenCV(Wiley,2014)

    video processing to detect and model moving objects; geometric operations & camera models; edge detection; features detection; recognition in images Contains a large number of vision application ...

    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 ...

    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 ...

    Debugging with GDB --2002年5.11

    r Switching between source languages s List of filename extensions and languages s Setting the working language s Having GDB infer the source language r Displaying the language r Type and range ...

    Beginning Python (2005).pdf

    Using Python Objects from C Code 380 Summary 383 Exercises 383 Chapter 18: Writing Shareware and Commercial Programs 385 A Case Study: Background 385 How Much Python Should You Use? 386 02_...

    UG6.0快捷键大全

    POPUP_MESSAGE Groups the selected features into a collection called a feature set. ACTIONS STANDARD END_OF_AFTER MENU UG_ARRANGE BUTTON/HIDE UG_MODELING_EDIT_GROUP_FEATURE LABEL Edit... ...

    C++ 标准 ISO 14882-2011

    Contents Contents iii List of Tables xi List of Figures xv 1 General 1 1.1 Scope . . . . ....1.2 Normative references ....1.3 Terms and definitions ....1.4 Implementation compliance ....1.5 Structure of this ...

Global site tag (gtag.js) - Google Analytics