Decorator pattern

With the Decorator pattern you can add behaviour to classes dynamically.

In this example I'll show you how to program a system to sell Tesla cars with many options (such as Auto Pilot). Each option affects the price of the car differently and a customer can choose many options or none at all. This is exactly the kind of problem that you can solve efficiently with a Decorator pattern.

Source code

Source code used in this video can be found on GitHub.

Like this video? Support me & subscribe to my channel: