Factory Method
The Factory Method differs from the ordinary Simple Factory on the basis that instead of us having one factory, we can have many.
So why would you want to do this? Well, in order to understand this, we must look to the open/closed principle (OCP). Bertrand Meyer is usually associated with having originated the term open/closed principle in his book, Object-oriented Software Construction. Meyer stated the following:
"software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification"
Where a software entity needs to be extended, this should be possible without modifying its source code. Those of you who are familiar with the SOLID (single responsibility, open-closed, Liskov substitution ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access