随笔分类 - Refactoring
Improving the Design of Existing Code-------Martin Fowler
All rights belongs to Martin Fowler.
Click this link for detail:http://www.refactoring.com/catalog/
摘要:You need to interface with a record structure in a traditional programming environment. Make a dumb data object for the record.
阅读全文
摘要:A method returns a collection. Make it return a read-only view and provide add/remove methods.
阅读全文
摘要:There is a public field. Make it private and provide accessors.
阅读全文
摘要:You have a literal number with a particular meaning. Create a constant, name it after the meaning, and replace the number with it.
阅读全文
摘要:You have a two-way association but on class no longer needs features from the other. Drop the unneeded end of the association.
阅读全文
摘要:You have two classes that need to use each other’s features, but there is only a one-way link. Add back pointers, and change modifiers to update both sets.
阅读全文
摘要:You have domain available only in a GUI control, and domain methods need access. Copy the data to a domain object. Set up an observer to synchronize the two pieces of data.
阅读全文
摘要:You have a reference object that is small, immutable, and awkward to manage. Turn it into a value object. To convert this to a value object, the key thing to do is verify that the object is immutabl...
阅读全文
摘要:You have an array in which certain elements mean different things. Replace the array with an object that has a field for each element.
阅读全文
摘要:You have a class with many equal instances that you want to replace with a single object. Turn the object into a reference object.
阅读全文
摘要:You have a data item that needs additional data or behavior. Turn the data item into an object.
阅读全文
摘要:You are accessing a field directly, but the coupling to the field is becoming awkward. Create getting and setting methods for the field and use only those to access the field.
阅读全文
摘要:A server class you are using needs several additional methods, but you can’t modify the class. Create a new class that contains these extra methods. Make this extension class a subclass or a wrapper ...
阅读全文
摘要:A server class you are using needs an additional method, but you can’t modify the class. Create a method in the client class with an instance of the server class as its first argument.
阅读全文
摘要:A class is doing too much simple delegation. Get the client to call the delegate directly.
阅读全文
摘要:A client is calling a delegate class of an object. Create methods on the server to hide the delegate.
阅读全文
摘要:A class isn’t doing very much. Move all its features into another class and delete it.
阅读全文
摘要:You have one class doing work that should be done by two. Create a new class and move to relevant fields and methods from the old class into the new class.
阅读全文
摘要:A field is, or will be, used by another class more than the class on which It is defined. Create a new field in the target class, and change all its users.
阅读全文
摘要:A method is, or will be, using or used by more features of another class than the class on which it is defined. Crete a new method with a similar body in the class it uses most. Either turn the old me...
阅读全文

浙公网安备 33010602011771号