Lably
Skip to content

Factory method pattern

Object-oriented software design pattern

  • 18 min read
  • 5 chapters

Related on Lably

Through Object-oriented programming, Class (programming) and Constructor (object-oriented programming)

Overview

The factory method design pattern solves problems such as:

  • How can an object's subclasses redefine its subsequent and distinct implementation? The pattern involves creation of a factory method within the superclass that defers the object's creation to a subclass's factory method.
  • How can an object's instantiation be deferred to a subclass? Create an object by calling a factory method instead of directly calling a constructor.

This enables the creation of subclasses that can change the way in which an object is created (for example, by redefining which class to instantiate).

Sign in to keep reading

4 more chapters are free with a Lably account.

More in Computing and communication