« Design Patterns » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
Aucun résumé des modifications |
Aucun résumé des modifications |
||
Ligne 1 : | Ligne 1 : | ||
[[Category:CSharp]] | [[Category:CSharp]] | ||
[[Category:Informatique Générale]] | [[Category:Informatique Générale]] | ||
= Decorator | = Structural patterns = | ||
* [[Decorator]] | |||
* | * Proxy | ||
* | * Bridge | ||
* | * Composite | ||
* Flyweight | |||
* Adapter | |||
* Facade | |||
== | = Creational patterns = | ||
* Prototype | |||
* Factory method | |||
* Singleton | |||
* | |||
* | |||
* | |||
== | = Behavioral patterns = | ||
* Strategy | |||
* State | |||
* Template method | |||
* Chain of responsablity | |||
* Command | |||
* Iterator | |||
* Mediator | |||
* Observer | |||
* Visitor | |||
* Interpreter | |||
* Memento | |||
= [http://www.dofactory.com/Patterns/PatternFactory.aspx Factory Method] = | = [http://www.dofactory.com/Patterns/PatternFactory.aspx Factory Method] = |
Version du 6 juin 2020 à 16:15
Structural patterns
- Decorator
- Proxy
- Bridge
- Composite
- Flyweight
- Adapter
- Facade
Creational patterns
- Prototype
- Factory method
- Singleton
Behavioral patterns
- Strategy
- State
- Template method
- Chain of responsablity
- Command
- Iterator
- Mediator
- Observer
- Visitor
- Interpreter
- Memento
Factory Method
Permet d'instancier des objets dont les classes (Lion, Wolf) ne sont directement connues par l'appelant (AnimalsFactory).
Mais elles héritent toutes d'une classe abstraite (Animal) qui elle est connue de l'appelant.
Singleton
public class Singleton { private Singleton() { } private static readonly Singleton _instance = new Singleton(); public static Singleton Instance { get { return _instance; } } } |
Double-checked locking
public class Singleton { private static readonly object Lock = new object(); private static readonly Singleton _instance; private Singleton() { } public static Singleton Instance { get { if (_instance == null) { lock (_lock) { if (_instance == null) { _instance = new Singleton(); } } } } // permet d'implémenter un set, là où Lazy ne le permet pas } } // In .NET Framework 4.0, the Lazy<T> class was introduced, which internally uses double-checked locking by default public class Singleton { private static readonly Lazy<Singleton> _instance = new Lazy<Singleton>(() => new Singleton()); private Singleton() { } public static Singleton Instance { get { return _instance.Value; } } } |
Abstract Factory
Fournit une interface (ContinentFactory) pour créer des familles d'objets (Carnivore, Herbivore) sans avoir besoin de connaitre l'implémentation de ces classes (Lion, Wildebeest, Wolf, Bison).
Builder
Factorise le code de plusieurs