Object-Oriented Design Patterns #3 — Factory Method

Object-oriented design patterns series — Factory Method. Short notes in plain English, use cases and live examples.

Bohdan Balov 🇺🇦
2 min readApr 23, 2022
Picture from Unsplash by Matteo Stroppaghetti

MAIN

PREVIOUS

Factory Method is a creational OO design pattern. It is useful when a program should flexibly operate with several classes following the same interface. Classes of the same interface are called “Products”. The key point here is that a client code knows only about the “Product” interface and nothing about the specific implementations.

Just imagine a situation when you want to change your bicycle for a newer one. You are not concerned about the implementation details thinking about how to ride it — you already know how to spin pedals and steer it! (See the “D” principle from SOLID.)

Use Cases

  • Multiplatform UI components library
  • A set of different Employee classes: Admin, Writer, Reviewer…

UML Diagram

UML Diagram of Factory Method Design Pattern
UML Diagram of Factory Method Design Pattern

Example

TypeScript code example may be found in my GitHub repo.

Also, there is a visualization of how this pattern may be used on my GitHub page. This is a contrived example, so, don’t judge too strong, please.

References

NEXT (coming soon…)

--

--

Bohdan Balov 🇺🇦

Lead Software Engineer at EPAM Systems | Mentor | Writer | Crazy Runner from Brave Ukraine