Design patterns. Decorator in examples

Artem Diashkin
Jul 25, 2020 · 3 min read

“Decorator pattern” is a structural type pattern that adds new features without modifying existing code structure, which allow not to break old functionality.

Concepts

This pattern will be very useful if you are working on a legacy app, or if you need to add some new functionality to sealed classes (third-party library), or if you want to follow “Single responsibility principle” and “Open Closed Principle” in your current app.

Design

UML diagram

Examples

Example 1:

Base notify
SMS NOTIFY
Facebook NOTIFY
Telegram NOTIFY

Example 2:

Example 3:

Other Structural patterns

Contrast with related patterns

Composite pattern:

Decorator pattern:

LITSLINK

LITSLINK’s team is sharing their experience

Sign up for LITSLINK Newsletter

By LITSLINK

It's a test newsletter! Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Artem Diashkin

Written by

Java, Spring, Node.js, AdonisJs, React.js and Flutter developer

LITSLINK

LITSLINK

Hands-on up to date experience sharing of the most skilled & talented software developers right here, right now. Subscribe to learn & understand more about the Software World.

Artem Diashkin

Written by

Java, Spring, Node.js, AdonisJs, React.js and Flutter developer

LITSLINK

LITSLINK

Hands-on up to date experience sharing of the most skilled & talented software developers right here, right now. Subscribe to learn & understand more about the Software World.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface.

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox.

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic.

Get the Medium app