SlideShare a Scribd company logo
C# Design Patterns Jason Townsend Bartlesville .NET User Group
The Gang of Four Available at  http://www.is.gd/wlb Has become the reference book for design patterns. Prerequisite for understanding modern patterns.
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.
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.
Abstract Factory Groups object factories that have a common theme.
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.
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.
Builder Pattern Constructs complex objects by separating construction and representation.
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.
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.
Factory Method Pattern Creates objects without specifying the exact class to create.
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.
Prototype Pattern Creates objects by cloning an existing object.
Singleton Pattern Restricts object creation for a class to only one instance
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.
Singleton in .NET Framework Singletons are used with .NET remoting when launching server-activated objects.  Through the Singleton activation mode.
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.
Adapter Pattern Allows classes with incompatible interfaces to work together by wrapping it’s own interface around that of an already existing class.
Bridge Pattern Decouples an abstraction from its implementation so that the two can vary independently
Composite Pattern Composes one-or-more similar objects so that they can be manipulated as one object.
Decorator Pattern Dynamically adds/overrides behavior in an existing method of an object.
Façade Pattern Provides a simplified interface to a large body of code
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.
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.
Flyweight Pattern Reduces the cost of creating and manipulating a large number of similar objects
Proxy Pattern Provides a placeholder for another object to control access, reduce cost, and reduce complexity
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 .
Chain of Responsibility Pattern Delegates commands to a chain of processing objects.
Command Pattern Creates objects which encapsulate actions and parameters.
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.
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.
Interpreter Pattern Implements a specialized language.
Iterator Pattern Accesses the elements of an object sequentially without exposing its underlying representation.
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.
Iterator in .NET Framework Iterator is actually a part of the .NET language itself: Foreach IEnumerable / IEnumerator Array, ArrayList, AttributesCollection, Generics
Mediator Pattern Allows loose coupling between classes by being the only class that has detailed knowledge of their methods.
Memento Pattern Provides the ability to restore an object to its previous state (undo).
Observer Pattern Publish/subscribe pattern which allows a number of observer objects to see an event.
State Pattern Allows an object to alter its behavior when its internal state changes.
Strategy Pattern Allows one of a family of algorithms to be selected on-the-fly at runtime.
Template Pattern Defines the skeleton of an algorithm as an abstract class, allowing its subclasses to provide concrete behavior.
Visitor Pattern Separates an algorithm from an object structure by moving the hierarchy of methods into one object.
 
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]

More Related Content

PPT
Design Patterns (Examples in .NET)
PDF
Design patterns difference between interview questions
DOCX
Java Design Pattern Interview Questions
PPT
Design Pattern For C# Part 1
PPTX
Gof design patterns
PDF
Basic design pattern interview questions
PDF
Aspect Oriented Programming Through C#.NET
PDF
Aspect-Oriented Programming and Depedency Injection
Design Patterns (Examples in .NET)
Design patterns difference between interview questions
Java Design Pattern Interview Questions
Design Pattern For C# Part 1
Gof design patterns
Basic design pattern interview questions
Aspect Oriented Programming Through C#.NET
Aspect-Oriented Programming and Depedency Injection

What's hot (19)

PPT
Structural patterns
PPTX
How I Learned To Apply Design Patterns
PDF
Lecture 5 Software Engineering and Design Design Patterns
PDF
GOF Design pattern with java
PPTX
Let us understand design pattern
PPT
ASPECT ORIENTED PROGRAMING(aop)
PPTX
Design patterns
PPT
Design patterns
PPTX
PPTX
Dependency Inversion Principle
DOCX
25 java tough interview questions
PDF
Gof design pattern
PPTX
GoF Design patterns I: Introduction + Structural Patterns
PPT
Software Design Patterns
PPS
Jump start to OOP, OOAD, and Design Pattern
PPTX
Inversion of control
PPTX
Design patterns creational patterns
PPT
Adapter Design Pattern
KEY
Spring AOP
Structural patterns
How I Learned To Apply Design Patterns
Lecture 5 Software Engineering and Design Design Patterns
GOF Design pattern with java
Let us understand design pattern
ASPECT ORIENTED PROGRAMING(aop)
Design patterns
Design patterns
Dependency Inversion Principle
25 java tough interview questions
Gof design pattern
GoF Design patterns I: Introduction + Structural Patterns
Software Design Patterns
Jump start to OOP, OOAD, and Design Pattern
Inversion of control
Design patterns creational patterns
Adapter Design Pattern
Spring AOP
Ad

Similar to Bartlesville Dot Net User Group Design Patterns (20)

PPTX
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
DOCX
Patterns (contd)Software Development ProcessDesign patte.docx
PPT
Design pattern
DOCX
Design patterns
PPT
P Training Presentation
PDF
Gang of Four in Java
PPTX
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
PPT
Design Pattern with Actionscript
PPTX
Software design and Architecture.pptx
PPT
Jump Start To Ooad And Design Patterns
PPT
Introduction To Design Patterns
PPT
Software Design Patterns
PDF
Java Design Patterns Interview Questions PDF By ScholarHat
PPTX
Common ASP.NET Design Patterns - Telerik India DevCon 2013
PPT
Design Patterns
PPTX
Evolution of Patterns
DOCX
Hibernate3 q&a
PPT
ActionScript Design Patterns
PPTX
Design patterns
KEY
Practical OOP In Java
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Patterns (contd)Software Development ProcessDesign patte.docx
Design pattern
Design patterns
P Training Presentation
Gang of Four in Java
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern with Actionscript
Software design and Architecture.pptx
Jump Start To Ooad And Design Patterns
Introduction To Design Patterns
Software Design Patterns
Java Design Patterns Interview Questions PDF By ScholarHat
Common ASP.NET Design Patterns - Telerik India DevCon 2013
Design Patterns
Evolution of Patterns
Hibernate3 q&a
ActionScript Design Patterns
Design patterns
Practical OOP In Java
Ad

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Cloud computing and distributed systems.
PPTX
Big Data Technologies - Introduction.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Encapsulation theory and applications.pdf
PDF
Machine learning based COVID-19 study performance prediction
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Approach and Philosophy of On baking technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Cloud computing and distributed systems.
Big Data Technologies - Introduction.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Review of recent advances in non-invasive hemoglobin estimation
Encapsulation_ Review paper, used for researhc scholars
MIND Revenue Release Quarter 2 2025 Press Release
Encapsulation theory and applications.pdf
Machine learning based COVID-19 study performance prediction
The AUB Centre for AI in Media Proposal.docx
MYSQL Presentation for SQL database connectivity
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Per capita expenditure prediction using model stacking based on satellite ima...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Approach and Philosophy of On baking technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Digital-Transformation-Roadmap-for-Companies.pptx

Bartlesville Dot Net User Group Design Patterns

  • 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]