Better Programming

Advice for programmers.

Follow publication

Member-only story

5 Reasons Why You Should Know The Composite Design Pattern

jsmanifest
Better Programming
Published in
4 min readJan 18, 2022
Photo by Mohammad Rahmani on Unsplash

The composite pattern can be your swiss-army knife when developing dynamic user interfaces. When we develop web applications we work with the DOM on the client-side. This is perfect because of how the DOM is structured.

The goal is to compose more than one object into a certain tree structure representing a part-whole hierarchy.

A part-whole relationship is when each object in a collection is a part of the whole composition. This “whole” composition is a collection of parts. When we think of a part-whole hierarchy, it’s a tree structure where each individual “leaf” or “node” is treated the same as every other leaf or node in the tree, allowing them to be worked with uniformly in our program. This means that a collection or group of objects (sub-tree of leaf/nodes) is also a leaf or node.

Here is how it looks like when we look at it from a visual perspective:

In software engineering, developers can take advantage of the pattern where they need to work with deeply nested objects and not have to worry much about the implementation details afterward. This is a powerful technique that can help solve complex problems as we will see in this post.

In this post, I will explain the reasons why composite Design Pattern is crucial to know.

You can work with collections the same way you can with single objects

Working in uniformity with objects and collections of objects is already powerful.

You most likely already worked with code that uses it. If you are familiar with the DOM then you’re already familiar with traversing children off of DOM nodes

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

jsmanifest
jsmanifest

Written by jsmanifest

Team Lead Front End Developer for a TeleMedicine Company. Follow and Join Me on my Adventures. https://jsmanifest.com

No responses yet

Write a response