...

/

Behavioral Design Patterns

Behavioral Design Patterns

Get introduced to behavioral design patterns and learn to use them.

What are behavioral patterns?

Behavioral design patterns define how objects communicate and collaborate to accomplish tasks within a system. These patterns focus on effective interaction and responsibility-sharing among objects, without requiring significant changes to their internal code. This approach makes software systems more flexible, easier to maintain, and adaptable to future requirements.

For example, while designing a notification system, we might want to send an email, a push notification, or a text message whenever a new blog post is published. Instead of writing separate code for each type, we can use the observer pattern, which automatically updates all notification services when something new happens. If we decide to add a Slack message later, we simply introduce a new observer—no changes are needed in the main publishing code.

Several well-known behavioral design patterns exist. The most common patterns include Chain of Responsibility, Command, Iterator, Mediator, Observer, Visitor, Interpreter, Memento, State, Strategy, and Template Method. This lesson will explain the most important and commonly used patterns to help build a strong understanding of practical design and interview preparation.

The illustration below shows all the patterns that fall under this category:

Press + to interact

Chain of Responsibility pattern

The Chain of Responsibility pattern allows a request sent by a client to be received by more than one object. It creates a chain of loosely-coupled objects that, upon receiving the request, either handle it or pass it to the next handler object.

A common example of this pattern is event bubbling in the DOM. An event propagates through different nested elements of the DOM until one of them handles it.

Command pattern

The Command pattern allows ...