The Composite design pattern has the intention to represent part-whole as your friends on social media or a tower, as in the picture below.

Tokyo skytree tower

Why this pattern?

Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly [1].

Using a composite structure, we can apply the same operations over both composites and individual objects. In other words, in most cases, we can ignore the differences between compositions of objects and individual objects.[2]



The diagrams below show how to identify this pattern and the participants.

When do you need to connect things, one of the options is to build a bridge, and this pattern is an example of it in code time upfront of integrations.

Forth Railway Bridge, Scotland
  • For more about this bridge, click here.


Excerpt from GOF book[1],

When an abstraction can have one of several possible implementations, the usual way to accommodate them is to use inheritance. An abstract class defines the interface to the abstraction, and concrete subclasses implement it in different ways. But this approach isn’t always flexible enough. …

Working with Lists is a common task in Java, but this task should be done carefully whether the unmodifiable or immutable is required.


1. Why?

This article covers the change inside the elements of the List in order to avoid problems, for instance: Where is the element nth? Why did the element have one value and now has another value?

Retain the data as is, and don’t allow any element change, if required or a man in the middle.

1.1. Unmodifiable

The term unmodifiable means that the structure of the List itself cannot be altered[1].

If the elements in the List are mutable (which…

It was a kind 😆 of weird, handle all the Kubernetes (k8s) commands on my local environment and then I decided to install the k8s dashboard.

Expected result

What kind of problem the dashboard solve?

Solve the problem to see a GUI instead of CLI. Although help when you’re starting on k8s and/or won’t have in mind all k8s commands, there are so many, check it out.

  • Has Helm installed
  • You’re using kind
  • If you’re using other local k8s, such as Minikube check the section Minikube.

How to configure?

Install the dashboard using the following steps:

  1. Helm install
helm install dashboard kubernetes-dashboard/kubernetes-dashboard -n kubernetes-dashboard --create-namespace

After for the umpteenth time type the command port-forward I noticed that I had to use Ingress 😜 and avoid the famous DRY (Don’t Repeat Yourself).

Disclaimer → Is not wrong use port-forward command, but if you can don’t remember it, looks great.

Assumptions → You’re familiar with docker and has installed the softwares below.

For this tutorial I’m using the following softwares

In terms of deploy, I’m using an application built with Quarkus, with 2 endpoints, /resteasy-jackson/quarks and /hello-resteasy. The image is available on my Docker hub.

This is an overview of those piece together…

Let’s play on my brand new video game? I can’t because my old television doesn’t support the video game interface. May you already face this situation someday.



Excerpt from GOF book

How can existing and unrelated classes work in an application that expects classes with a different and incompatible interface? [1]


Excerpt from GOF book,

you want to use an existing class, and its interface does not match the one you need.

you want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that don’t necessarily have compatible interfaces.

(object adapter only) you need…

Disclaimer ⚠️. Even though this pattern belongs to the code smell section in Java, worth knows it and recognize and know what is your purpose.

Below we can see the prototypes of Stormtrooper since for me they’re always equals.

Stormtrooper clones


Use the Prototype Pattern when a client needs to create a set of objects that are alike or differ from each other only in terms of their state and creating an instance of a such object (e.g., using the “new” keyword) is either expensive or complicated.[7]


Excerpt from GOF book,

Use the Prototype pattern when a system should be independent of…

This pattern works together with the factory method, my last article before it, and creates a family of objects. Based on that, let’s see your structure and how to implement it.

Abstract factory

What did I use as references?

To write this article I used the Gang Of Four, Head First Design Patterns, and Wikipedia. All the links are available in the References section.

Consider a user interface toolkit that supports multiple look-and-feel standards, such as Motif and Presentation Manager. Different look-and-feels define different appearances and behaviors for user interface “widgets” like scroll bars, windows, and buttons. To be portable across look-and-feel standards, an application should not hard-code…

Sometimes everything we want is the simplest way to create an object, and this object helps us to achieve this goal. This article is based on the Gang Of Four book and uses JUnit5 to execute the tests.

Factory picture


Frameworks use abstract classes to define and maintain relationships between objects. A framework is often responsible for creating these objects as well.[1]


Handles object creation and encapsulates it in a subclass. This decouples the client code in the superclass from the object code in this subclass.[5]

Where can I use this pattern?

This pattern can be used based on motivation and applicability sections, moreover to make system design…

Alone, this word defines Singleton’s behavior. In this article, I’ll show the benefits and some code examples in Spring, Quarkus, and writing by my own Singleton class.

Design Pattern Singleton


It’s important for some classes to have exactly one instance. Although there can be many printers in a system, there should be only one printer spooler. There should be only one file system and one window manager. A digital filter will have one A/D converter. An accounting system will be dedicated to serving one company.[3]


There must be exactly one instance of a class, and it must be accessible to clients from a…

Luiz Gustavo De O. Costa

Hi there 👋 , I’m Luiz Gustavo I’m a Brazilian and don’t play soccer very well, then I became a software developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store