Enterprise Application Architecture with .NET Core
by Ganesan Senthilvel, Ovais Mehboob Ahmed Khan, Habib Qureshi
The factory method pattern
The factory method pattern basically specifies the interface to create an object without specifying its exact class. This pattern primarily focuses on creating only one type of object specified by the interface for the object to be created.
For example, in our application, we want to use a weather service to get the current weather of a given city. What we need is a reference to the weather service object, and what the factory method abstracts out is that we need a weather service reference without knowing where this actual object reference is coming from. For example, it can be from Yahoo weather, AccuWeather, or even a fake weather service object that can be used for testing.
In the section for .NET Core dependency ...
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