Refactoring Declaration (2) - Taking Features between Objects

xiaoxiao2021-03-06  54

Movement Features between Objects MOVE METHOD If a method makes more communication with another class other than Source Class (call or call), a new method of establishing a similar behavior is created in another Class. The original method becomes a delegating method, or completely deleted it. During the movement, if the method needs to use the features of the Source Class, there are several options: 1. Move this feature to Target Class 2, establish or use a reference relationship from Target Class to Source Class 3, speak Source Object is transmitted to Target method 4 as a parameter. If the feature is a variable, it is passed as a parameter to Target Method Move Field If a Field is used by another class other than its Source Class. Just establish a new field in Target Class, modify all users of Source Field, so they use them new field. You must delete Source Field to ensure that the access function has changed the operation object. Extrat Class has a Class to do too much work, you should create a new Class to move exendable Field and Method from Source Class to Target Class. A Class should be a clear abstraction and handle some clear responsibilities. Inline Class If a class is not doing too much thing (no sufficient responsibility), move all the characteristics of this Class to another Class and then delete the original Class. Hide delegate establishes all the functions required for the Server (a class) to hide the delegation relationship. A simple entrusting method can be placed on the Server end and hide the commission relationship. This will even be restricted to the server even if there is a change in the relationship in the future, and the change will be restricted to the server. The Remove Middle Man has a simple delegation action for a Class. You can transfer the client directly to the delegate class. For convenience, we may want to retain some of the delegate relationships. In addition, we may also want some customers to hide the commission relationship and allow other use and direct use of the delegate object. For these reasons, some simple entrustment relationships may also be left in place. Introduce Foreign Method requires additional methods in using Server Class, but cannot modify this Class. A method can be created in the Client Class and take this Server Class entity as the first quotient. If you find yourself for a Server Class, a large number of additional methods are found, or there are many Class, you need to use the same plus method, do not use this reconstruction, use Introduce Local Extension. Introducture Local Extension requires some additional methods in using Server Class, but it cannot modify this Class. A new Class can be created to enable it to include these additional methods. Let this extended Class becomes the SUBCLASS or Wrapper (Outer Clay) of Source Class.

转载请注明原文地址:https://www.9cbs.com/read-81631.html

New Post(0)