+ All Categories
Home > Technology > Bartlesville Dot Net User Group Design Patterns

Bartlesville Dot Net User Group Design Patterns

Date post: 15-Jan-2015
Category:
Upload: jason-townsend
View: 3,461 times
Download: 0 times
Share this document with a friend
Description:
 
Popular Tags:
25
C# Design Patterns Jason Townsend Bartlesville .NET User Group
Transcript
Page 1: Bartlesville Dot Net User Group Design Patterns

C# Design PatternsJason TownsendBartlesville .NET User Group

Page 2: Bartlesville Dot Net User Group Design Patterns

The Gang of Four•Available at http://www.is.gd/wlb

•Has become the reference book for design patterns.

•Prerequisite for understanding modern patterns.

Page 3: Bartlesville Dot Net User Group Design 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.

Page 4: Bartlesville Dot Net User Group Design Patterns

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.

Page 5: Bartlesville Dot Net User Group Design Patterns

Factory Method PatternCreates objects without specifying the exact class to create.

Page 6: Bartlesville Dot Net User Group Design Patterns

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.

Page 7: Bartlesville Dot Net User Group Design Patterns

Singleton PatternRestricts object creation for a class to only one instance

Page 8: Bartlesville Dot Net User Group Design Patterns

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.

Page 9: Bartlesville Dot Net User Group Design Patterns

Singleton in .NET Framework

•Singletons are used with .NET remoting when launching server-activated objects. Through the Singleton activation mode.

Page 10: Bartlesville Dot Net User Group Design Patterns

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.

Page 11: Bartlesville Dot Net User Group Design Patterns

Façade PatternProvides a simplified interface to a large body of code

Page 12: Bartlesville Dot Net User Group Design Patterns

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.

Page 13: Bartlesville Dot Net User Group Design Patterns

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.

Page 14: Bartlesville Dot Net User Group Design Patterns

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.

Page 15: Bartlesville Dot Net User Group Design Patterns

Command PatternCreates objects which encapsulate actions and parameters.

Page 16: Bartlesville Dot Net User Group Design Patterns

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.

Page 17: Bartlesville Dot Net User Group Design Patterns

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.

Page 18: Bartlesville Dot Net User Group Design Patterns

Iterator PatternAccesses the elements of an object sequentially without exposing its underlying representation.

Page 19: Bartlesville Dot Net User Group Design Patterns

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.

Page 20: Bartlesville Dot Net User Group Design Patterns

Iterator in .NET Framework

•Iterator is actually a part of the .NET language itself:▫Foreach▫IEnumerable / IEnumerator▫Array, ArrayList, AttributesCollection,

Generics

Page 21: Bartlesville Dot Net User Group Design Patterns

Observer Pattern

Publish/subscribe pattern which allows a number of observer objects to see an event.

Page 22: Bartlesville Dot Net User Group Design Patterns

State Pattern

Allows an object to alter its behavior when its internal state changes.

Page 23: Bartlesville Dot Net User Group Design Patterns

Strategy PatternAllows one of a family of algorithms to be selected on-the-fly at runtime.

Page 24: Bartlesville Dot Net User Group Design Patterns
Page 25: Bartlesville Dot Net User Group Design Patterns

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


Recommended