150 likes | 372 Views
Object-Oriented Design Patterns. All about me. Lee Brandt – Gemini Blog: http://www.codebucket.org Shout Outs: Geeks With Blogs http://www.geekswithblogs.net Dot Net User’s Group http://www.kcdotnet.com http://groups.google.com/group/kcdotnet. Agenda. What Design Patterns are
E N D
All about me Lee Brandt – Gemini Blog: http://www.codebucket.org Shout Outs: Geeks With Blogs http://www.geekswithblogs.net Dot Net User’s Group http://www.kcdotnet.comhttp://groups.google.com/group/kcdotnet
Agenda • What Design Patterns are • Why you should know them • The categories of Patterns • The Patterns themselves • Where you might (already) use them • When NOT to use a Design Pattern
What Are Design Patterns? • Names for Commonly Solved Problems • Elements of Reusable OO Software • Gang of Four • Erich Gamma • Richard Helm • Ralph Johnson • John Vlissides • Code Complete • Steve McConnell • Patterns of Enterprise Architecture • Martin Fowler
Why Should You Care? • Common Vocabulary • Discussing software design • Easy Understanding • Someone has already solved this problem • Proven Good Design • Understanding others’ code
Get to the Patterns Fat Boy. • Pattern Categories • Creational • Structural • Behavioral • Pastoral • Pastoral-Comical • Historical-Pastoral • Tragical-Historical • Tragical-Comical-Historical…
Creational Patterns • Factory Method • Used to create a concrete instance of a type • Abstract Factory • Creates Families of like objects • Builder • Used when an object can take multiple steps to instantiate • Prototype • Creates an object by “copying” itself from a base • Singleton • Ensures that only one instance of an object exists
Structural Patterns • Adapter • Makes an object of one interface look like another interface for the consuming client • Bridge • Decouples an object’s interface from its implementation • Composite • A tree structure of simple and composite objects • Decorator • Add responsibilities to an object dynamically • Façade • Single class that simplifies access to an entire subsystem • Flyweight • A small instance managed by a list of state data • Proxy • An object that stands in for another object
Behavioral Patterns • Chain of Responsibility • A way of passing a request between a chain of objects • Command • Encapsulate a command request as an object • Interpreter • A way to include language elements in a program • Iterator • Sequentially access the elements of a collection • Mediator • Defines simplified communication between classes
Behavioral Patterns continued… • Memento • Capture and restore an object's internal state • Observer • A way of notifying change to a number of classes • State • Changes an object’s behavior when its state changes • Strategy • Encapsulates an algorithm inside a class • Template Method • Defer the exact steps of an algorithm to a subclass • Visitor • Defines a new operation to a class without change
Adapter Pattern Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.
You already use patterns • If you use: • .Net Framework • Iterator – GetEnumerator() • Composite – List • Strategy – IComparable • Observer – Event Handlers • Chain Of Responsibility – Event Handlers • WCF / Web Services • Proxy – Web Methods
Continued… • Test-Driven or Behavior-Driven Development • Bridge – Mock Objects • Dependency Injection • Factory – DI Container • Bridge – Interface -> Implementation • MVC/MVP • Mediator – Presenter/Controller • Strategy – Presenter/Controller • Composite – View • Observer – Model
For More Info • Reading • Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, et al. • Head First Design Patterns by Eric Freeman & Elisabeth Freeman • C# Design Patterns by James W. Cooper • Links • http://www.dofactory.com/Patterns/Patterns.aspx • http://c2.com/cgi/wiki?GangOfFour