Structural Design Pattern in Java

Structural Design Pattern in Java

According to Wikipedia, in software engineering, Structural Design Patterns in Java are Design Patterns that ease the design by identifying a simple way to realize the relationship among entities. In simple words, we can say that the Structural Design Pattern is basically used to manage the structure of classes and interface as well as manage the relationship between the classes. These Design Patterns work with class and object composition and use inheritance to write interfaces and obtain new functionality.

When to use Structural Design Patterns in Java?

In real-time applications, sometimes we need to change the structure of a class or the relationship among the classes but we don’t want this change to be affected by the project. For example, if we have two classes let’s say User and Product. And the Product class is used inside the User class making one-to-many relationships between the User and Product. Tomorrow, the structure or the relationships between these two classes change. The customer now wants to keep away the Product class from the User class, as they want to use the User and Product class independently. This is actually a structural change and we don’t want this structural change to affect our project. This is where the Structural Design Pattern helps us.

Structural Design Patterns Examples in Java

The following patterns are included under structural design patterns:

  1. Adapter Design Pattern: This pattern connects two incompatible interfaces by providing a wrapper for a class or object that uses a different interface, allowing it to be used with another interface.
  2. Bridge Design Pattern: This pattern separates an abstraction from its implementation so that it can change independently. It achieves this by separating the interface from the implementation without using inheritance.
  3. Composite Design Pattern: This pattern organizes objects into tree structures to represent part-whole hierarchies and allows clients to treat individual objects and compositions of objects in the same way.
  4. Decorator Design Pattern: This pattern adds new functionality to an existing object without changing its structure by wrapping it with additional functionality.
  5. Facade Design Pattern: This pattern simplifies access to a complex subsystem by providing a simplified interface that hides the complexities of the system.
  6. Flyweight Design Pattern: This pattern minimizes memory usage by sharing as much data as possible with other similar objects, reducing the number of objects created.
  7. Proxy Design Pattern: This pattern controls access to another object by providing a surrogate or placeholder for it. It creates an intermediary that acts as an interface to another resource.

In the next article, I am going to discuss the Adapter Design Pattern in Java with Examples. Here, in this article, I try to give a brief introduction to Structural Design Patterns in Java. I hope you understand the need for and use of the Structural Design Pattern in Java.

Leave a Reply

Your email address will not be published. Required fields are marked *