Refactoring To Patterns Part-1
1 — Chain Constructors*
You have multiple constructors that contain duplicate code, Chain the constructors together to obtain the least duplicate code.
2 — Replace Multiple Constructors with Creation Methods*
Many constructors on a class make it hard to decide which constructor to call during development, Replace the constructors with Creation Methods that return object instances.
3 — Encapsulate Subclasses with Creation Methods*
Subclasses implement a common interface but are constructed in diverse ways, Encapsulate the subclasses with intention-revealing Creation Methods in the base class
Motivation :
1-The motivation for doing this refactoring is to hide implementation details from those who don’t need to know about them.
2-the door is closed for changing the subclass interface in response to the needs of client code.
4 — Extract Creation Class*
Too many Creation Methods on a class obscure its primary responsibility (or responsibilities) break the single responsibility principle, Move the Creation Methods for a related set of classes to one Creation Class.