Tag: designpatterns

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