- Building a Complex object using simple objects – step by step
Where to use ?
- To make a complex object by specifying only its type and content.
- To decouple the process of building a complex object from the parts that make up the object.
- Isolate code for construction and representation.
- To get finer control over the construction process.
Implementation example
- Item interface implemented by abstract classes Burger, Fries, ColdDrink
- Multiple concrete classes : CheeseBurger, FishBurger and ChickenBerger extending Burger class
- Multiple concrete classes : Coke, Pepsi and ThumsUp extending ColdDrink class
- A class Meal having list of Item objects
- A class MealBuilder to prepare different kind of meals
- Client will use MealBuilder class to prepare meal as per need without knowing complexity of its creation.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.