["Refactoring"] ---- [[TableOfContents]] = Chapter 7 Moving Features Between Objects = == Move Method == A method is, or will be, using or used by more features of another class than the class on which it is defined. ''Create a new method with a similar body in the class it uses most. Either turn the old method into a simple delegation, or remove it altogether.'' http://zeropage.org/~reset/zb/data/MoveMethod.gif == Move Field == 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.'' http://zeropage.org/~reset/zb/data/MoveField.gif == Extract Class == You have one class doing work that should be done by two. ''Create a new class and move the relevant fields and methods from the old class into the new class.'' http://zeropage.org/~reset/zb/data/1012450988/ExtractClass.gif == Inline Class == A class isn't doing very much. ''Move all its features into another class and delete it.'' http://zeropage.org/~reset/zb/data/InlineClass.gif == Hide Delegate == A client is calling a delegate class of an object. ''Create methods on the server to hide the delegate.'' http://zeropage.org/~reset/zb/data/HideDelegate.gif == Remove Middle Man == A class is doing too much simple delegation. ''Get the client to call the delegate directly.'' http://zeropage.org/~reset/zb/data/RemoveMiddleMan.gif == Introduce Foreign Method == 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.'' {{{~cpp Date newStart = new Date (previousEnd.getYear(), previousEnd.getMonth(), previousEnd.getDate() + 1); }}} {{{~cpp Date newStart = nextDay (previousEnd); private static Date nextDay (Date arg) { return new Date (arg.getYear(), arg.getMonth(), arg.getDate() + 1); } }}} == Introduce Local Extension == A server class you are using needs serveral additional methods, but you can't modify the class. ''Create a new class that contains these extra methods. Make the extension class a subclass or a wapper of the original.'' http://zeropage.org/~reset/zb/data/IntroduceLocalExtension.gif ---- ["Refactoring"]