You are on page 1of 1

Duplicate Code

Pattern Description
Form Template Method Remove explicit or subtle duplication in sub classes of hierarchy.
Polymorphic creation with If a method in sub classes is implemented similarly except object
factory method creation.
Chaining Constructor When constructor of classes contain duplicate code
Replace One/many Separate code processing of single object or collection of objects
distinction with Composite
Extract Composite If sub classes of hierarchy each implement their own composite and
implementation may be identical.
Unify Interfaces with Adaptor If code process objects differently merely because they have different
interfaces
Introduce Null Object If you have conditional logic to deal with an object when object is null
and same null logic is duplicated throughout the system.

Long Method
Pattern Description
Composed Method This involves extract method.
Replace Conditional If method contain long switch statement for dispatching and handling
Dispatcher with Command requests.
Move accumulator to Visitor If method contains switch statements to gather data from numerous
classes with different interfaces.
Replace conditional logic with If method contains numerous version of algorithm and conditional logic
Strategy to choose different versions at runtime.

You might also like