What is the Factory Method Design Pattern in Java?

Factory Method Design Pattern define an interface for creating an object, but let subclass decide which class to instantiate. Factory Method lets a class defer instantiation to subclass.

Below is the explanation of the above image:

  • The factory method in the interface lets a class defer the instantiation to one or more concrete subclasses.
  • Since these design patterns talk about the instantiation of an object they come under the category of creational design pattern.
  • If we notice the name Factory method, that means there is a method which is a factory, and in general, factories are involved with creational stuff and here with this, an object is being created.
  • It is one of the best ways to create an object where object creation logic is hidden from the client. Now Let’s look at the implementation.

Factory method design pattern in Java

It is a creational design pattern that talks about the creation of an object. The factory design pattern says to define an interface ( A java interface or an abstract class) for creating the object and let the subclasses decide which class to instantiate.

Important Topics for the Factory method design pattern in Java

  • What is the Factory Method Design Pattern in Java?
  • When to use Factory Method Design Pattern in Java?
  • Key Components of Factory Method Design Pattern
  • Factory Method Design Pattern Example in Java
  • Use Cases of the Factory Method Design Pattern in Java
  • Advantages of Factory Method Design Pattern in Java
  • Disadvantages of Factory Method Design Pattern in Java

Similar Reads

What is the Factory Method Design Pattern in Java?

Factory Method Design Pattern define an interface for creating an object, but let subclass decide which class to instantiate. Factory Method lets a class defer instantiation to subclass....

When to use Factory Method Design Pattern in Java?

Factory method design pattern can be used in java in following cases:...

Key Components of Factory Method Design Pattern

...

Factory Method Design Pattern Example in Java

Problem Statement...

Use Cases of the Factory Method Design Pattern in Java

...

Advantages of Factory Method Design Pattern in Java

...

Disadvantages of Factory Method Design Pattern in Java

Here are some common applications of the Factory Method Design pattern in Java:...

Conclusion

The advantages of Factory Method Design Pattern in Java are:...