Design Patterns and Refactoring
Creational Patterns
1.
Abstract Factory
The purpose of the Abstract Factory is to provide an interface for creating families of related objects, without specifying concrete classes (more...)
2.
Builder
The Builder pattern separates the construction of a complex object from its representation so that the same construction process can create different representations (more...)
3.
Factory Method
The Factory Method defines an interface for creating objects, but lets subclasses decide which classes to instantiate (more...)
4.
Object Pool
Object pools are used to manage the object caching and it can offer a significant performance boost (more...)
Structural Patterns
7.
Adapter
The Adapter pattern allows otherwise incompatible classes to work together by converting the interface of one class into an interface expected by the clients (more...)
8.
Bridge
The Bridge pattern decouples an abstraction from its implementation, so that the two can vary independently (more...)
9.
Composite
The Composite composes objects into tree structures and lets clients treat individual objects and compositions uniformly (more...)
10.
Decorator
The Decorator attaches additional responsibilities to an object dynamically. Decorator pattern suggests giving the client the ability to specify whatever combination of "features" is desired (more...)
11.
Facade
The Facade defines a unified, higher level interface to a subsystem that makes it easier to use (more...)
12.
Flyweight
The Flyweight pattern describes how to share objects to allow their use at fine granularities without prohibitive cost (more...)
13.
Private Class Data
The private class data design pattern seeks to reduce exposure of attributes by limiting their visibility (more...)
Behavioral Patterns
15.
Chain of Responsibility
Chain of Responsibility chains the receiving objects together, and then passes any request messages from object to object until it reaches an object capable of handling the message (more...)
16.
Command
The Command pattern allows requests to be encapsulated as objects, thereby allowing clients to be parameterized with different requests (more...)
17.
Interpreter
The Intepreter pattern defines a grammatical representation for a language and an interpreter to interpret the grammar (more...)
18.
Iterator
The Iterator provides ways to access elements of an aggregate object sequentially without exposing the underlying structure of the object.
(more...)
19.
Mediator
The Mediator defines an object that controls how a set of objects interact. Loose coupling between colleague objects is achieved by having colleagues communicate with the Mediator, rather than with each other (more...)
20.
Memento
The Memento captures and externalizes an object's internal state so that the object can later be restored to that state (more...)
21.
Null Object
The Null Object encapsulates the absence of an object by providing a substitutable alternative that offers suitable default "do nothing" behavior (more...)
22.
Observer
The Observer defines a one-to-many relationship so that when one object changes state, the others are notified and updated automatically (more...)
23.
State
The State pattern allows an object to change its behavior when its internal state changes (more...)
24.
Strategy
The Strategy lets the algorithm vary independently from the clients that use it. It defines a family of algorithms, encapsulates each one, and makes them interchangeable (more...)
25.
Template Method
The Template Method defines a skeleton of an algorithm in an operation, and defers some steps to subclasses (more...)
Composing Methods of Refactoring
27.
Extract Method
If you have a code fragment that can be grouped together, turn the fragment into a method whose name explains the purpose of the method (more...)
28.
Inline Method
If a method's body is just as clear as its name, put the method's body into the body of its callers and remove the method (more...)
29.
Inline Temp
If you have a temp that is assigned to once with a simple expression, and the temp is getting in the way of other refactorings, replace all references to that temp with the expression (more...)
30.
Introduce Explaining Variable
If you have a complicated expression, put the result of the expression, or parts of the expression, in a temporary variable with a name that explains the purpose (more...)
32.
Replace Method with Method Object
If uou have a long method that uses local variables in such a way that you cannot apply Extract Method, turn the method into its own object so that all the local variables become fields on that object (more...)
33.
Replace Temp with Query
If you are using a temporary variable to hold the result of an expression, extract the expression into a method. Replace all references to the temp with the expression. The new method can then be used in other methods (more...)
34.
Split Temporary Variable
If you have a temporary variable assigned to more than once, but is not a loop variable nor a collecting temporary variable, make a separate temporary variable for each assignment (more...)
34.
Substitute Algorithm
If you want to replace an algorithm with one that is clearer, replace the body of the method with the new algorithm (more...)
Moving Features Between Objects
35.
Extract Class
If 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 (more...)
36.
Hide Delegate
If a client is calling a delegate class of an object, create methods on the server to hide the delegate (more...)
37.
Inline Class
If a class isn't doing very much, move all its features into another class and delete it (more...)
38.
Introduce Foreign Method
If 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 (more...)
39.
Introduce Local Extension
If 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 of the original (more...)
40.
Move Field
If 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 (more...)
41.
Move Method
If 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 (more...)
42.
Remove Middle Man
If a class is doing too much simple delegation, get the client to call the delegate directly (more...)
Organizing Data
46.
Change Value to Reference
If you have a class with many equal instances that you want to replace with a single object, turn the object into a reference object (more...)
47.
Duplicate Observed Data
If you have domain data 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 (more...)
50.
Replace Array with Object
If you have an array in which certain elements mean different things, replace the array with an object that has a field for each element (more...)
54.
Replace Subclass with Fields
If you have subclasses that vary only in methods that return constant data, change the methods to superclass fields and eliminate the subclasses (more...)
58.
Introduce Explaining Variable
If you have a complicated expression, put the result of the expression, or parts of the expression, in a temporary variable with a name that explains the purpose (more...)
60.
Self Encapsulate Field
If 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 (more...)
Simplifying Conditional Expressions

63.
Decompose Conditional
If you have a complicated conditional (if-then-else) statement, extract methods from the condition, then part, and else parts (more...)
64.
Introduce Assertion
If a section of code assumes something about the state of the program, make the assumption explicit with an assertion (more...)
66.
Remove Control Flag
If you have a variable that is acting as a control flag for a series of boolean expressions, use a break or return instead (more...)
67.
Replace Conditional with Polymorphism
If you have a conditional that chooses different behavior depending on the type of an object, move each leg of the conditional to an overriding method in a subclass. Make the original method abstract (more...)
Making Method Calls Simpler
69.
Add Parameter
If a method needs more information from its caller, add a parameter for an object that can pass on this information (more...)
70.
Encapsulate Downcast
If a method returns an object that needs to be downcasted by its callers,
move the downcast to within the method (more...)
71.
Hide Method
If a method is not used by any other class, make the method private (more...)
73.
Hide Delegate
If a client is calling a delegate class of an object, create methods on the server to hide the delegate (more...)
74.
Parameterize Method
If several methods do similar things but with different values contained in the method body, create one method that uses a parameter for the different values (more...)
75.
Preserve Whole Object
If you are getting several values from an object and passing these values as parameters in a method call, send the whole object instead (more...)
78.
Rename Method
If the name of a method does not reveal its purpose, change the name of the method (more...)

81.
Replace Exception with Test
If you are throwing a checked exception on a condition the caller could have checked first, change the caller to make the test first (more...)
83.
Replace Parameter with Method
If an object invokes a method, then passes the result as a parameter for a method. The receiver can also invoke this method, remove the parameter and let the receiver invoke the method (more...)
84.
Separate Query from Modifier
If you have a method that returns a value but also changes the state of an object, create two methods, one for the query and one for the modification (more...)
Dealing with Generalization
86.
Extract Interface
If several clients use the same subset of a class's interface, or two classes have part of their interfaces in common, extract the subset into an interface (more...)
87.
Extract Subclass
If a class has features that are used only in some instances, create a subclass for that subset of features (more...)

88.
Replace Array with Object
If you have an array in which certain elements mean different things, replace the array with an object that has a field for each element (more...)
90.
Extract Superclass
If you have two classes with similar features, create a superclass and move the common features to the superclass (more...)
91.
Form Template Method
If you have two methods in subclasses that perform similar steps in the same order, yet the steps are different, get the steps into methods with the same signature, so that the original methods become the same. Then you can pull them up (more...)
92.
Pull Up Constructor Body
If you have constructors on subclasses with mostly identical bodies, create a superclass constructor; call this from the subclass methods (more...)
94.
Pull Up Method
If you have methods with identical results on subclasses, move them to the superclass (more...)
96.
Push Down Method
If behavior on a superclass is relevant only for some of its subclasses, move it to those subclasses (more...)

98.
Replace Inheritance with Delegation
If a subclass uses only part of a superclasses interface or does not want to inherit data, create a field for the superclass, adjust methods to delegate to the superclass, and remove the subclassing (more...)
Big Refactorings
100.
Extract Hierarchy
If you have a class that is doing too much work, at least in part through many conditional statements, create a hierarchy of classes in which each subclass represents a special case (more...)
101.
Tease Apart Inheritance
If you have an inheritance hierarchy that is doing two jobs at once, create two hierarchies and use delegation to invoke one from the other (more...)








