Abstract Factory, Factory Method, Builder

A builder helps you construct a complex object. An example is the StringBuilder class (Java, C#), which builds the final string piece by piece. A better example is the UriComponentsBuilder in Spring, which helps you build a URI. A factory method gives you a complete object in one shot (as opposed to the builder). A … Read more

What is the difference in case of intent and application between these two Patterns? [closed]

With the Factory pattern, you produce instances of implementations (Apple, Banana, Cherry, etc.) of a particular interface — say, IFruit. With the Abstract Factory pattern, you provide a way for anyone to provide their own factory. This allows your warehouse to be either an IFruitFactory or an IJuiceFactory, without requiring your warehouse to know anything … Read more

Avoiding all DI antipatterns for types requiring asynchronous initialization

This is a long answer. There’s a summary at the end. Scroll down to the summary if you’re in a hurry. The problem you have, and the application you’re building, is a-typical. It’s a-typical for two reasons: you need (or rather want) asynchronous start-up initialization, and Your application framework (azure functions) supports asynchronous start-up initialization … Read more

Factory, Abstract Factory and Factory Method

The Gang Of Four “Design Patterns; Elements of Reusable Object-Oriented Software” book contains two entries, “Abstract Factory” (aka ‘Virtual Constructor’) and “Factory Method”. I don’t know about “Concrete Factory.” I’ve heard the term, but never given it too much thought. Factory Method In “Factory Method” an object has a method which is responsible for the … Read more

Is the Service Locator pattern any different from the Abstract Factory pattern?

I have stumbled across the same question while investigating these patterns. I think the major differences can be found between a Service Locator and a Factory (whether it is abstract or not): Service Locator ‘Locates’ an existing dependency (the service). Although the service may be created during resolution, it is of no consequence to the … Read more

Why do we need Abstract factory design pattern?

Abstract Factory is a very central design pattern for Dependency Injection (DI). Here’s a list of Stack Overflow questions where application of Abstract Factory has been accepted as the solution. To the best of my understanding, these questions represent real concerns or problems that people had, so that should get you started with some real-life … Read more

Design Patterns: Abstract Factory vs Factory Method

Hope this helps. It describes the various types of factories. I used the Head First Design Patterns book as my reference. I used yuml.me to diagram. Static Factory Is a class with a Static Method to product various sub types of Product. Simple Factory Is a class that can produce various sub types of Product. … Read more

What is the difference between Factory and Strategy patterns?

A factory pattern is a creational pattern. A strategy pattern is an operational pattern. Put another way, a factory pattern is used to create objects of a specific type. A strategy pattern is use to perform an operation (or set of operations) in a particular manner. In the classic example, a factory might create different … Read more