Tag: structural

  • How to implement Proxy pattern in Java?

    Let’s say you want to load a file from a server. There is an API available which does the actual action of loading the file. But calling it every time overloads the server. Instead you can introduce a proxy in between which will fetch the file the first time and then put it on cache.…

  • How to implement Flyweight pattern in Java?

    Let’s say you are an artist. You want to create different Color Palettes using three colors at a time. The three colors can be anything of all colors know to us. Let’s represent this in Java code using Flyweight pattern and check what problems it solves. Flyweight pattern let’s you reuse objects instead of creating…

  • How to implement Facade pattern in Java?

    Facade is one of the easiest patterns to implement. And if one has not come across the “Gang of Four Design Patterns” they probably already would have used facade pattern. Facade just provides a single interface to a set of sub systems. Let me explain. Let’s say you are writing an application for an eCommerce…

  • How to implement decorator pattern in Java?

    Let’s say you are designing a house, an apartment house. You have done the base design. And now you want to add some more to your design. Let’s do that using Decorator pattern. A decorator pattern lets you add responsibilities to an existing object without changing its existing functionality. An alternate way of achieving this…

  • How to implement Composite pattern in Java?

    Let’s say you are the manager of a project. You have been asked to calculate the total cost to your company of your entire team. You have a service development team with two members. You have a UI development team with two members. You have a Quality Assurance team with two members. You have a…

  • How to implement Bridge pattern in Java?

    Let’s say you are a technical manager. You have several projects under you. You have designed them already to use different client and server technologies. Client technologies include Angular , VueJS and React. Server technologies include Java, DotNet and NodeJS. You are combining these two categories in different combinations and using each combination for a…