Tutorial by Examples

A factory decreases coupling between code that needs to create objects from object creation code. Object creation is not made explicitly by calling a class constructor but by calling some function that creates the object on behalf the caller. A simple Java example is the following one: interface Ca...
Abstract factory pattern provides a way to obtain an coherent collection of objects through a collection of factories functions. As for every pattern, coupling is reduced by abstracting the way a set of objects are created, so that the user code is unaware of the many details of the objects he needs...
Factories can be used in conjunction with Inversion of Control (IoC) libraries too. The typical use case for such a factory is when we want to create an object based on parameters that are not known until run-time (such as the current User). In these cases it can be sometimes be difficult (if no...
The following design pattern is categorized as a creational pattern. An abstract factory is used to provide an interface for creating families of related objects, without specifying concrete classes and can be used to hide platform specific classes. interface Tool { void use(); } interf...
Intent: Define an interface for creating an object, but let sub classes decide which class to instantiate. Factory Method lets a class defer instantiation to sub classes. UML diagram: Product: It defines an interface of the objects the Factory method creates. ConcreteProduct: Implements Produc...
In simple words: A Flyweight factory that for a given, already known, key will always give the same object as response. For new keys will create the instance and return it. Using the factory: ISomeFactory<string, object> factory = new FlyweightFactory<string, object>(); var result1...
The Factory method pattern is a creational pattern that abstracts away the instantiation logic of an object in order to decouple the client code from it. When a factory method belongs to a class that is an implementation of another factory pattern such as Abstract factory then it is usually more ap...

Page 1 of 1