Author: Vijay SRJ

  • 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…

  • How to implement Adapter pattern in Java?

    Let’s say you love nuts. You buy them every now and then from a vendor named Raghav. You buy it online through a java program which calls Raghav’s shop API. Let’s say you have created a Shop interface to represent Raghav’s shop and created a class RaghavShop implementing it. And you have declared a method…

  • How to implement AbstractFactory pattern in Java?

    Let’s say you run a dress factory. And you want to create an application to manage manufacturing dress. You have a separate factory for manufacturing shirts and another factory for manufacturing pants. These are the factories which are going to do the actual manufacturing. But you create two more virtual factories (which don’t physically exist)…

  • How to implement Singleton pattern in Java?

    In most interviews when candidates are asked about design patterns , the first answer that pops up is Singleton pattern! This pattern has been beaten to pulp ever since design patterns became mainstream. Still people can go wrong in effectively implementing it. This post looks into this pattern in detail. Singleton , as the name…

  • How to implement Prototype pattern in Java?

    Lets say you run a modelling agency. You are creating an application to manage your models. They are of different types – actors, male and female , can do anchoring , can play the role of video jockey , can act in cinema etc. To design classes for the above use case , you could…

  • How to implement Factory Method pattern in Java?

    Lets say you want to sell headphones. You create an application to handle your sales. You create a generic HeadPhoneShop class which can handle creating(buying from the manufacturer) the head phones and sell them. But you don’t want it to do the actual creation. You want to delegate it a shop which deals with creating…

  • How to implement Builder pattern in Java

    Let’s prepare Vanjaram Fish Curry , a complex object in Java. Let’s use Builder Pattern right out of the books of the Gang of Four. In fact I bought this book recently and used the recipe given by them. Let’s start with the client code . This I believe gives a better perspective to decode…

  • How to communicate between Angular components using @ViewChild annotation

    In the previous post I showed how to communicate between two angular components using local template reference. The drawback using that strategy is that you can’t reference the child component inside parent component’s typescript code. It can be referenced only inside the parent template. This can be overcome by using @ViewChild annotation. This will inject…