Bartlesville Dot Net User Group Design Patterns

  • 3,412 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
3,412
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
246
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. C# Design Patterns Jason Townsend Bartlesville .NET User Group
  • 2. The Gang of Four
    • Available at http://www.is.gd/wlb
    • Has become the reference book for design patterns.
    • Prerequisite for understanding modern patterns.
  • 3. Why Design Patterns?
    • Design patterns draw on years of design expertise.
    • Using design patterns is reuse of tried software engineering techniques.
    • Design patterns create and efficient vocabulary for talking about software design.
  • 4. Creational Patterns
    • Abstract Factory
    • Builder
    • Factory Method
    • Prototype
    • Singleton
    These patterns have to do with class instantiation. They can be further divided into class-creation patterns and object-creational patterns. While class-creation patterns use inheritance effectively in the instantiation process, object-creation patterns use delegation to get the job done.
  • 5. Abstract Factory Groups object factories that have a common theme.
  • 6. Abstract Factory Details
    • High Frequency of Use
    • Good to use when you need more control over the creation process.
    • Beneficial for object caching, maintaining object counts, maintaining type counts, reuse of objects.
  • 7. Abstract Factory in .NET Framework
    • You can find the abstract factory pattern in the DbProviderFactory and the DbProviderFactories on the ADO .NET libraries.
    • Naming convention in the framework is to append Factory to the name of the type that will be created.
    • Used in Enterprise Library, Smart Client Factory, Web Services Factory, and Web Client Factory.
    • Try searching the Framework for more factories.
  • 8. Builder Pattern Constructs complex objects by separating construction and representation.
  • 9. Builder Details
    • Medium to Low Frequency of Use.
    • Used frequently for code generators.
    • Gives more control over each step of the creation process than the factory patterns.
  • 10. Builder in .NET Framework
    • Not widely used.
    • Can find in VBCodeProvider and CSharpCodeProvider with the CreateGenerator methods. These return a ICodeGenerator interface which can be used to control the code generation.
  • 11. Factory Method Pattern Creates objects without specifying the exact class to create.
  • 12. Factory Method Details
    • High frequency of use.
    • Use when the client application will not know which classes to instantiate.
    • Key objective of Factory Method Pattern is extensibility.
  • 13. Prototype Pattern Creates objects by cloning an existing object.
  • 14. Singleton Pattern Restricts object creation for a class to only one instance
  • 15. Singleton Pattern Details
    • High frequency of use.
    • A singleton can be used when you have an object that is created multiple times yet is stateless, this will improve performance.
    • Often used for global variables. Global variables are often considered a bad coding practice, however there are times when they are necessary.
  • 16. Singleton in .NET Framework
    • Singletons are used with .NET remoting when launching server-activated objects. Through the Singleton activation mode.
  • 17. Structural Patterns
    • Adapter
    • Bridge
    • Composite
    • Decorator
    • Façade
    • Flyweight
    • Proxy
    These concern class and object composition. They use inheritance to compose interfaces and define ways to compose objects to obtain new functionality.
  • 18. Adapter Pattern Allows classes with incompatible interfaces to work together by wrapping it’s own interface around that of an already existing class.
  • 19. Bridge Pattern Decouples an abstraction from its implementation so that the two can vary independently
  • 20. Composite Pattern Composes one-or-more similar objects so that they can be manipulated as one object.
  • 21. Decorator Pattern Dynamically adds/overrides behavior in an existing method of an object.
  • 22. Façade Pattern Provides a simplified interface to a large body of code
  • 23. Façade Pattern Details
    • High frequency of use.
    • Provide a unified interface to a set of interfaces in a subsystem.
    • More common pattern in 3-tier architecture modeled applications.
    • Hide the ugly.
    • Often implemented as singleton abstract factories.
    • Can implement using static methods on the Façade
    • Using Façade should be a conscious decisions. Facades take control away from the user of you API, and may decrease performance. Must way performance vs development time.
  • 24. Façade in .NET Framework
    • Microsoft calls them aggregate components, in component-oriented designs.
    • Can find in System.Diagnostics.EventLog, System.Web.Mail.SmtpMail, System.IO.SerialPort., System.Messaging.MessageQueue.
  • 25. Flyweight Pattern Reduces the cost of creating and manipulating a large number of similar objects
  • 26. Proxy Pattern Provides a placeholder for another object to control access, reduce cost, and reduce complexity
  • 27. Behavioral Patterns
    • Chain of Responsibility
    • Command
    • Interpreter
    • Iterator
    • Mediator
    • Memento
    • Observer
    • State
    • Strategy
    • Template Method
    • Visitor
    These design patterns are about classes objects communication. They are specifically concerned with communication between objects .
  • 28. Chain of Responsibility Pattern Delegates commands to a chain of processing objects.
  • 29. Command Pattern Creates objects which encapsulate actions and parameters.
  • 30. Command Pattern Details
    • High frequency of use.
    • Encapsulates an action or request as an object.
    • Classic usage is in menuing systems.
    • All commands implement the same interface, so they can be handled polymorphically.
    • Typically the interface include Do/Undo or Execute/Undo.
  • 31. Command in .NET Framework
    • Used in Smart Client Software Factory.
    • Used in Web Service Software Factory.
    • Used in Web Client Software Factory.
    • ADO.NET DbCommand.
    • Used in Visual Studio .NET for the menuing system, toolbars, etc…
    • One of the biggest complaints is the Microsoft did not include that pattern as part of a larger unified WinForms command routing architecture.
  • 32. Interpreter Pattern Implements a specialized language.
  • 33. Iterator Pattern Accesses the elements of an object sequentially without exposing its underlying representation.
  • 34. Iterator Pattern Details
    • High Frequency of Use
    • Used to traverse and manipulate a collection of objects.
    • Common traversals are front/back, back/front, every x object, etc…
    • Seperates the collection of objects from the traversal logic.
  • 35. Iterator in .NET Framework
    • Iterator is actually a part of the .NET language itself:
      • Foreach
      • IEnumerable / IEnumerator
      • Array, ArrayList, AttributesCollection, Generics
  • 36. Mediator Pattern Allows loose coupling between classes by being the only class that has detailed knowledge of their methods.
  • 37. Memento Pattern Provides the ability to restore an object to its previous state (undo).
  • 38. Observer Pattern Publish/subscribe pattern which allows a number of observer objects to see an event.
  • 39. State Pattern Allows an object to alter its behavior when its internal state changes.
  • 40. Strategy Pattern Allows one of a family of algorithms to be selected on-the-fly at runtime.
  • 41. Template Pattern Defines the skeleton of an algorithm as an abstract class, allowing its subclasses to provide concrete behavior.
  • 42. Visitor Pattern Separates an algorithm from an object structure by moving the hierarchy of methods into one object.
  • 43.  
  • 44. Further Resources
    • My Blog
      • http://www.okcodemonkey.com
    • Linkedin
      • http://www.linkedin.com/in/okcodemonkey
    • Bartlesville .NET User Group
      • http://www.bdnug.com
    • Twitter
      • http://twitter.com/okcodemonkey
    • Email
      • [email_address]