Software Development

Decorator pattern

The decorator pattern is a design pattern used to add new behaviors to objects without modifying their classes.

A practical example

Let’s say we have a Product interface that has a method that returns the cost of the product itself. We also have a Pasta class that implements Product.

Factory pattern

The factory pattern is used when we want to create a object without knowing the specific class of the object but only the interface that it implements or the abstract class it extends.

A practical example

In our example we have a Drawer class that has a method that takes the name of a geometric shape and draws it.