Design Pattern: Bridge Pattern in Java
Bridge pattern is used to decouple implementation and abstraction. This article demonstrates Bridge pattern implementations in Java.
Design Pattern Tutorials
Bridge pattern is used to decouple implementation and abstraction. This article demonstrates Bridge pattern implementations in Java.
Using Bridge we can decouple the implementation of UI Element and Color Schema, so the elements and colors will have a separate hierarchy. That way the implementation of the Elements and Color will be independent and the element color can be set dynamically.
Composite pattern is used to handle the operation of a bunch of classes (having the same interface), to operate the same function of all items a the same time. Using Composite pattern the client can ignore the difference between the Composition and Leaf classes, and can use the composition considering the same interface. This article demonstrates Composite pattern implementations in Java. Check the following examples.
When there is a bunch of classes that are of the same type (implement the same interface), and we need to use them as composition (not as individual objects), we can use Composite pattern. Composite pattern helps to use the classes in a composition, so that the client can use the composition and individual classes can be tread in the same way.
When there is a group of similar algorithms and we need a pattern to decide among those patterns, then we can use Strategy pattern.
In Decorator design pattern, our target is to add some new functionality to an existing object. Say, there is an existing class that is responsible for printing a UI element (like a Button or Table). Later we need the ability to add a border or text color to that element. We can add new properties and functions to that existing class and introduce those properties. But that will violate the Open-Close principle of the SOLID principle.
Decorator pattern is used to attach a new functionality to an existing object, without changing the existing class. This article demonstrates Decorator pattern implementations in Java.
In Proxy design pattern, an object represents another object. So one object works as a proxy of another object. A proxy object represents an interface to the client. The client will not access the actual object directly, it will always use the project object in all cases.
Flyweight pattern is used to reduce the number of objects to save memory and optimize resources. This article demonstrates Flyweight pattern implementations in Java. Check the following examples.
As we need to generate a huge number of objects of the same class, so it will occupy a big amount of memory. To avoid that, we can create objects with only the required elements and keep that in a cache. As only the required properties are there so the number of objects will be smaller now. As the only difference between those objects is their extrinsic properties, we will pass those properties while using that specific object.