Mohamed Meligy Senior Software Engineer Silverkey Tech
Mohamed Meligy Senior Software Engineer Silverkey Tech
net/meligy
Single Responsibility
You should not affect global properties
Open / Closed!
Extension / Modification
GoF
Once, there was a gang
Creational
The process of object creation
Strategy Command
You want only one instance to be exposed from your singleton class to your clients Players: Singleton The class that exposes only one object of itself Client The code that calls the instance from this class Example: HttpContext.Current
You want the client code to only call the interface, not the exact class that implements it Players: Abstract Factory Factory Product1, Product2, Client Example: Logging, Plugins
Provide an interface for creating families of dependent objects without specifying their concrete classes
GoF
Encapsulates the interface of some code inside another interface Players: Adaptee Target Adapter Client Example: Serialization, DTOs
Convert the interface of a class into another interface clients expect.
GoF
Define the strategy interface, and use it in other classes, even change it when needed. Players: Strategy ConcreteStrategy Context
Example: Domain Validation
Define a family of algorithms, encapsulate each one, and make them interchangeable.
GoF
Define the strategy interface, and use it in other classes, even change it when needed. Players: Command ConcreteCommand Client Invoker Encapsulate a request as an object, Receiver thereby letting you parameterize clients Example: with different requests, queue or log Queue, Logging, Undo requests, and support undoable
operations.
GoF
Direct
Duplicate Code (DRY) Large Method/Class (SoC) Long Parameter List (Single Responsibility) Comments Very Little Too Much
Indirect
Difficulty in changing class Difficulty in having new behavior Dependencies
GoF Patterns
Other Patterns
martinfowler.com (WARNING: java) codebetter.com/blogs/ david.hayden (book) Agile Principles Patterns, and Practices in C# msdn.microsoft.com/enus/library/aa137892.aspx
C# 3.0 Design Patterns (book OReilly) patterns.cs.up.ac.za/examples. shtml C# Design Patterns, A tutorial (book Addison Wesley) dofactory.com codeproject.com aspalliance.com