Builder Vs Decorator pattern [closed]

From wikipedia’s decorator pattern article:

In object-oriented programming, the
decorator pattern is a design pattern
that allows new/additional behaviour
to be added to an existing object

There’s no need to add toppings to a Pizza after it has been fully constructed. You don’t eat half a pizza and then add another topping to it.

In other words, the Builder Pattern makes it easy to construct an object which is extensible in independent directions at construction time, while the Decorator Pattern lets you add extensions to functionality to an object after construction time. Using the decorator pattern to construct objects is bad because it leaves the object in an inconsistent (or at least incorrect) state until all the required decorators are in place – similar to the JavaBean problem of using setters to specify optional constructor arguments.

Leave a Comment