Design Patterns. (and anti-patterns)

Similar documents
EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

Design Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.)

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

SDC Design patterns GoF

The Strategy Pattern Design Principle: Design Principle: Design Principle:

Socket attaches to a Ratchet. 2) Bridge Decouple an abstraction from its implementation so that the two can vary independently.

Object-oriented Software Design Patterns

Object-Oriented Oriented Programming

Design patterns. Jef De Smedt Beta VZW

Design Patterns. SE3A04 Tutorial. Jason Jaskolka

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Software Design COSC 4353/6353 D R. R A J S I N G H

Design Patterns: Structural and Behavioural

Object Oriented Paradigm

DESIGN PATTERN - INTERVIEW QUESTIONS

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011

Introduction to Software Engineering: Object Design I Reuse & Patterns

Using Design Patterns in Java Application Development

Brief Note on Design Pattern

Object-Oriented Design

Slide 1. Design Patterns. Prof. Mirco Tribastone, Ph.D

Design Patterns. Dr. Rania Khairy. Software Engineering and Development Tool

Design Patterns Reid Holmes

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

CS342: Software Design. November 21, 2017

1 Software Architecture

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Tuesday, October 4. Announcements

Application Architectures, Design Patterns

Design Patterns. An introduction

Topics in Object-Oriented Design Patterns

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011

Overview CS Kinds of Patterns. Design Pattern. Factory Pattern Rationale. Kinds of Factory Patterns

CSCI 253. Overview. The Elements of a Design Pattern. George Blankenship 1. Object Oriented Design: Iterator Pattern George Blankenship

Composite Pattern. IV.4 Structural Pattern

What is Design Patterns?

CSCI Object Oriented Design: Frameworks and Design Patterns George Blankenship. Frameworks and Design George Blankenship 1

Keywords: Abstract Factory, Singleton, Factory Method, Prototype, Builder, Composite, Flyweight, Decorator.

DESIGN PATTERNS MOCK TEST DESIGN PATTERNS MOCK TEST II

The Design Patterns Matrix From Analysis to Implementation

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

Object Oriented Methods with UML. Introduction to Design Patterns- Lecture 8

I, J. Key-value observing (KVO), Label component, 32 text property, 39

A Reconnaissance on Design Patterns

Design Pattern and Software Architecture: IV. Design Pattern

Software Eningeering. Lecture 9 Design Patterns 2

SYLLABUS CHAPTER - 1 [SOFTWARE REUSE SUCCESS FACTORS] Reuse Driven Software Engineering is a Business

Design Patterns Lecture 2

Applying Design Patterns to accelerate development of reusable, configurable and portable UVCs. Accellera Systems Initiative 1

Design Patterns. Comp2110 Software Design. Department of Computer Science Australian National University. Second Semester

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

Pro Objective-C Design Patterns for ios

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

Design Patterns Reid Holmes

Applying Design Patterns to SCA Implementations

Think of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern

Design Patterns. CSE870: Advanced Software Engineering (Design Patterns): Cheng

CS 349 / SE 382 Design Patterns. Professor Michael Terry January 21, 2009

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout

UNIT I Introduction to Design Patterns

Design Patterns! Acknowledgements!

DESIGN PATTERNS FOR MERE MORTALS

CSE 70 Final Exam Fall 2009

COSC 3351 Software Design. Design Patterns Behavioral Patterns (I)

What is Design Patterns?

DESIGNING, CODING, AND DOCUMENTING

Applying the Observer Design Pattern

CS 2720 Practical Software Development University of Lethbridge. Design Patterns

SOLID DESIGN PATTERNS FOR MERE MORTALS

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Design Patterns. Observations. Electrical Engineering Patterns. Mechanical Engineering Patterns

UNIT I Introduction to Design Patterns

THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS

Lecture 20: Design Patterns II

Creational Design Patterns

An Introduction to Patterns

Lecture 17: Patterns Potpourri. Copyright W. Howden 1

3 Product Management Anti-Patterns by Thomas Schranz

TDDB84: Lecture 6. Adapter, Bridge, Observer, Chain of Responsibility, Memento, Command. fredag 4 oktober 13

TDDB84. Lecture 2. fredag 6 september 13

Chapter 1. OO e OO. (Pattern) Alexander) (context) (elements) k. (issue) Š. (name) (classification)

Design Pa*erns. + Anima/on Undo/Redo Graphics and Hints

A few important patterns and their connections

Plan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade

Designing and Writing a Program. Divide and Conquer! The Design-Code-Debug Cycle. Documentation is Code. Pair Programming 3/8/2012

CSC207H: Software Design Lecture 6

Software Development Project. Kazi Masudul Alam

What is Design Patterns?

Writing your own Java I/O Decorator p. 102 Tools for your Design Toolbox p. 105 Exercise Solutions p. 106 The Factory Pattern Baking with OO

CS 370 Design Heuristics D R. M I C H A E L J. R E A L E F A L L

Factory Method. Comp435 Object-Oriented Design. Factory Method. Factory Method. Factory Method. Factory Method. Computer Science PSU HBG.

Design Patterns 2. Page 1. Software Requirements and Design CITS 4401 Lecture 10. Proxy Pattern: Motivation. Proxy Pattern.

CS560. Lecture: Design Patterns II Includes slides by E. Gamma et al., 1995

SOFTWARE PATTERNS. Joseph Bonello

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

Applying Some Gang of Four Design Patterns CSSE 574: Session 5, Part 3

Transcription:

Design Patterns (and anti-patterns)

Design Patterns The Gang of Four defined the most common object-oriented patterns used in software. These are only the named ones Lots more variations exist

Design Patterns Why are they useful? Common terminology Lots of example uses They promote re-use

Design Patterns The problem: Lots of buzzword sounding terms Some patterns very similar to others Patterns describe the general principle, not the implementation (delegation, message passing)

Non-OO Patterns General Cache, Buffer Lazy Initialization Functional Partial Application Continuation

Pattern Categories Three categories of patterns exist: Creational Managing class instances Structural Relationships between classes (API) Behavioral Communication between objects

Familiar Patterns

Familiar Patterns Singleton Ensure a class has only one instance, and provide a global Creational point of access to it. Easy to use, but introduces dependencies. Iterator Observer Factory Visitor Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation. Define a one-to-many dependency between objects so that when one object changes state, all its listeners are notified. Create objects without specifying their concrete class, decoupling code and adding flexibility. Many ways to implement. Delegate work to another object, often while iterating over a collection, avoiding switch statements and monolithic code.

Familiar Patterns Singleton Ensure a class has only one instance, and provide a global point of access to it. Easy to use, but introduces dependencies. Iterator Provide a way to access the elements of an array / list / dict Behavioral sequentially without exposing its underlying representation. Observer Factory Visitor Define a one-to-many dependency between objects so that when one object changes state, all its listeners are notified. Create objects without specifying their concrete class, decoupling code and adding flexibility. Many ways to implement. Delegate work to another object, often while iterating over a collection, avoiding switch statements and monolithic code.

Familiar Patterns Singleton Iterator Ensure a class has only one instance, and provide a global point of access to it. Easy to use, but introduces dependencies. Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation. Observer Define a one-to-many dependency between objects so that Behavioral when one object changes state, all its listeners are notified. Factory Visitor Create objects without specifying their concrete class,decoupling code and adding flexibility. Many ways to implement. Delegate work to another object, often while iterating over a collection, avoiding switch statements and monolithic code.

Familiar Patterns Singleton Iterator Observer Ensure a class has only one instance, and provide a global point of access to it. Easy to use, but introduces dependencies. Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation. Define a one-to-many dependency between objects so that when one object changes state, all its listeners are notified. Factory Create objects without specifying their concrete class, decoupling Creational code and adding flexibility. Many ways to implement. Visitor Delegate work to another object, often while iterating over a collection, avoiding switch statements and monolithic code.

Familiar Patterns Singleton Iterator Observer Factory Ensure a class has only one instance, and provide a global point of access to it. Easy to use, but introduces dependencies. Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation. Define a one-to-many dependency between objects so that when one object changes state, all its listeners are notified. Create objects without specifying their concrete class, decoupling code and adding flexibility. Many ways to implement. Visitor Delegate work to another object, often while iterating over a collection, Behavioral avoiding switch statements and monolithic code.

Familiar Patterns Singleton EventManager.Instance.EventQueue(); Iterator while (iter.movenext()) { Console.WriteLine(iter.Current()); Observer widget.addlistener(this, OnClick ); Factory newwidget = WidgetFactory.Create(WidgetType.Button); Visitor for (var visitor : objects) { visitor.printon(this);

Familiar Patterns Singleton EventManager.Instance.EventQueue(); Iterator while (iter.movenext()) { Console.WriteLine(iter.Current()); Observer widget.addlistener(this, OnClick ); Factory newwidget = WidgetFactory.Create(WidgetType.Button); Visitor for (var visitor : objects) { visitor.printon(this);

Familiar Patterns Singleton EventManager.Instance.EventQueue(); Iterator while (iter.movenext()) { Console.WriteLine(iter.Current()); Observer widget.addlistener(this, OnClick ); Factory newwidget = WidgetFactory.Create(WidgetType.Button); Visitor for (var visitor : objects) { visitor.printon(this);

Familiar Patterns Singleton EventManager.Instance.EventQueue(); Iterator while (iter.movenext()) { Console.WriteLine(iter.Current()); Observer widget.addlistener(this, OnClick ); Factory newwidget = WidgetFactory.Create(WidgetType.Button); Visitor for (var visitor : objects) { visitor.printon(this);

Familiar Patterns Singleton EventManager.Instance.EventQueue(); Iterator while (iter.movenext()) { Console.WriteLine(iter.Current()); Observer widget.addlistener(this, OnClick ); Factory newwidget = WidgetFactory.Create(WidgetType.Button); Visitor for (var visitor : objects) { visitor.printon(this); // Double-dispatch (delegate)

Familiar Patterns [Extended] Null Object Object Pool Abstract the handling of null away from the client by introducing Null objects or Null subclasses. This pattern should be used carefully as it can make errors/bugs appear as normal program execution. Create and re-use objects instead of creating and destroying them. Speeds up use and reduces garbage. [UITableView dequeuereusablecellwithidentifier:]

Familiar Patterns, Unfamiliar Names

Familiar Patterns, Unfamiliar Names Builder Chain of Responsibility Facade Template Method Prototype Proxy Separate the construction of complex objects from its representation. Avoid coupling by allowing a chain of objects to handle the request. The search is over when one objects reports that it has handled the request. Wraps a complicated subsystem with a simpler interface. Also helps abstract APIs such as Facebook. Commonly seen as *Helper in our code. Define the skeleton of an algorithm in an operation, deferring some steps to client subclasses. An abstract class that needs placeholder methods filled in. Create new objects by cloning existing ones. Makes it easy to create templates at runtime. Similar to the Factory pattern. Provide a placeholder for another object to control access to it. Used to make remote objects look local, and for logging, access control, etc.

Familiar Patterns, Unfamiliar Names Builder Chain of Responsibility Facade Template Method Prototype Proxy Separate the construction of complex objects from its representation. Avoid coupling by allowing a chain of objects to handle the request. The search is over when one objects reports that it has handled the request. Wraps a complicated subsystem with a simpler interface. Also helps abstract APIs such as Facebook. Commonly seen as *Helper in our code. Define the skeleton of an algorithm in an operation, deferring some steps to client subclasses. An abstract class that needs placeholder methods filled in. Create new objects by cloning existing ones. Makes it easy to create templates at runtime. Similar to the Factory pattern. Provide a placeholder for another object to control access to it. Used to make remote objects look local, and for logging, access control, etc.

Familiar Patterns, Unfamiliar Names Builder Chain of Responsibility Facade Template Method Prototype Proxy Separate the construction of complex objects from its representation. Avoid coupling by allowing a chain of objects to handle the request. The search is over when one objects reports that it has handled the request. Wraps a complicated subsystem with a simpler interface. Also helps abstract APIs such as Facebook. Commonly seen as *Helper in our code. Define the skeleton of an algorithm in an operation, deferring some steps to client subclasses. An abstract class that needs placeholder methods filled in. Create new objects by cloning existing ones. Makes it easy to create templates at runtime. Similar to the Factory pattern. Provide a placeholder for another object to control access to it. Used to make remote objects look local, and for logging, access control, etc.

Familiar Patterns, Unfamiliar Names Builder Chain of Responsibility Facade Template Method Prototype Proxy Separate the construction of complex objects from its representation. Avoid coupling by allowing a chain of objects to handle the request. The search is over when one objects reports that it has handled the request. Wraps a complicated subsystem with a simpler interface. Also helps abstract APIs such as Facebook. Commonly seen as *Helper in our code. Define the skeleton of an algorithm in an operation, deferring some steps to client subclasses. An abstract class that needs placeholder methods filled in. Create new objects by cloning existing ones. Makes it easy to create templates at runtime. Similar to the Factory pattern. Provide a placeholder for another object to control access to it. Used to make remote objects look local, and for logging, access control, etc.

Familiar Patterns, Unfamiliar Names Builder Chain of Responsibility Facade Template Method Prototype Proxy Separate the construction of complex objects from its representation. Avoid coupling by allowing a chain of objects to handle the request. The search is over when one objects reports that it has handled the request. Wraps a complicated subsystem with a simpler interface. Also helps abstract APIs such as Facebook. Commonly seen as *Helper in our code. Define the skeleton of an algorithm in an operation, deferring some steps to client subclasses. An abstract class that needs placeholder methods filled in. Create new objects by cloning existing ones. Makes it easy to create templates at runtime. Similar to the Factory pattern. Provide a placeholder for another object to control access to it. Used to make remote objects look local, and for logging, access control, etc.

Familiar Patterns, Unfamiliar Names Builder Chain of Responsibility Facade Template Method Prototype Proxy Separate the construction of complex objects from its representation. Avoid coupling by allowing a chain of objects to handle the request. The search is over when one objects reports that it has handled the request. Wraps a complicated subsystem with a simpler interface. Also helps abstract APIs such as Facebook. Commonly seen as *Helper in our code. Define the skeleton of an algorithm in an operation, deferring some steps to client subclasses. An abstract class that needs placeholder methods filled in. Create new objects by cloning existing ones. Makes it easy to create templates at runtime. Similar to the Factory pattern. Provide a placeholder for another object to control access to it. Used to make remote objects look local, for logging, access control, etc.

Builder Pattern Separate the construction of a complex object from its representation so that the same construction process can create different representations. Related to the Factory Pattern. public class AnimatorBuilder { public AnimationBuilder Rotate(float angle) {... public AnimationBuilder Translate(float x, float y) {... Animation animation = new AnimatorBuilder().Rotate(45).Translate(10, 10).Build();

Chain of Responsibility Pattern Separate the construction of a complex object from its representation so that the same construction process can create different representations. Example: [view nextresponder] public class Widget { public void SendEvent(Event event) { while (!widget.handleevent(event)) { widget = widget.nextresponder;

Facade Pattern Wraps a complicated system with a simpler interface. Also helps abstract APIs such as Facebook. Commonly seen as *Helper classes in our code. public class LoginHelper { public static void Login() { // Do a bunch of complicated stuff here // Internal implementation can change LoginHelper.Login(); // Implementation and complexity is hidden

Template Method Pattern Define the skeleton of an algorithm in an operation, deferring some steps to client subclasses. An abstract class that needs placeholder methods filled in. Quintessential OO. public abstract class Widget { public void Draw() { this.drawrect(this.bounds); public virtual void DrawRect(Rect rect); // Override this method to do something useful widget.draw();

Prototype Pattern Create new objects by cloning existing ones. Makes it easy to create templates at runtime and provides more flexibility. Similar to the Factory pattern. public class Widget { public Widget Clone() { Widget widget = new Widget(); widget.copypropertiesfrom(self); return widget; LabelWidget newlabel = titlelabel.clone();

Proxy Pattern Provide a placeholder for another object to control access to it. Makes remote objects look local, or can be used as a conduit for logging or access control. Similar to Decorator, but does not add or enhance functionality. Implemented via delegation or reflection. interface ICanvas { void DrawLine(float x, float y); class CanvasLoggingProxy : ICanvas { private ICanvas canvas; public void DrawLine(float x, float y) { this.canvas.drawline(x, y);

Fuzzy/Unclear Patterns

Fuzzy/Unclear Adapter Convert the interface of a class into another interface clients expect. Bridge Use interfaces instead of abstract classes to decouple interface from impl. Composite Allows clients treat individual objects and compositions of objects uniformly. Decorator Wrap an object to provide additional features, using the same interface. Flyweight Use sharing to support large numbers of fine-grained objects efficiently. Private Class Data Encapsulate class data initialization, separating data from methods that use it. Command Encapsulate a function call parameter as an object, enabling logging, undo, oo-callbacks, etc. aka Action. Interpreter Execute a sequence of commands, enabling dynamic execution, batching. Mediator Design an intermediary to decouple many peers, which promotes loose coupling. Memento Allow an object to restore itself back to its previous state (e.g. undo ). State Allow an object to alter its behavior when its internal state changes. Strategy Define a family of algorithms, encapsulate each one, and make them interchangeable.

Adapter Pattern Convert the interface of a class into another interface clients expect. Used to encapsulate glue code. Related to the Facade pattern, but much smaller in scope: System vs class. Iterator uses Adapter. public interface IIndexable<T> { T ObjectAtIndex(int index); public class ArrayAdapter<T> : IIndexable { private array[t]; public T ObjectAtIndex(int index) { return self.array[index];

Bridge Pattern Use interface inheritance to decouple interface from implementation. Avoids inheritance explosion by not subclassing and only inheriting interfaces. Flexible, but may bloat code because of non re-use. interface IStreamReader { public char Read(); interface IStreamWriter { public void Write(char c); class ReadWriteStream : IStreamReader, IStreamWriter { public char Read() { public void Write(char c) { class WriteStream : ReadStream { class ReadWriteStream : WriteStream {

Composite Pattern Allows clients treat individual objects and compositions of objects uniformly. Examples: UIView - Views with children treated the same as views with no children. Files and folders in Finder / Explorer. public interface Node { public int Name(); public class File : Node { public int Name() { public class Folder : Node { private Node[] children; public int Name() {

Decorator Pattern Wrap an object to provide additional features, using the same interface. Alternative to subclassing. Related: Proxy Pattern, Delegation. Adds or extends an object, vs Proxy which intercepts. interface IDrawable { public void Draw(); class BackgroundDecorator : IDrawable { private IDrawable drawable; public void Draw() { this.drawbackground(), this.drawable.draw(); canvas.adddrawable(new BackgroundDecorator(new Drawable()));

Flyweight Pattern Use sharing to support large numbers of fine-grained objects efficiently. Process vs thread, view vs grid cell: View draws cells, instead of a View per cell. Saves memory, possibly more performant. class GridCell { public void drawonview(widget widget) { class GridView : Widget { List<GridCell> cells; foreach (cell in this.cells) { cell.drawonview(this); // Also using visitor pattern here

Private Data Class Pattern Encapsulate class data initialization, separating data from methods that use it. Used to protect like protected, but within the class itself. Can be thought of as a non-sharable model class. class Customer { private struct Data { private string name; public string Name() { return name; private data; public Customer(string name) { this.data = Data() { name ;

Fuzzy/Unclear/Rare Patterns Part 2

Command Pattern Encapsulate a function call parameter as an object, enabling logging, undo, callbacks, etc. aka Action. Combine with other patterns: Command + Interpreter = Macro. Related: Closure (functional equivalent) public class RotateImageAction { private float angle; public RotateImageAction(float angle) { this.angle = angle; public execute() { image.executeaction(new RotateImageAction(45));

Interpreter Pattern Execute a sequence of commands, enabling dynamic execution, batching. Can be a syntactic language or simply an Abstract Syntax Tree, a model representing syntax structure. Related: Command Pattern, Composite Pattern List<IAction> actions = new List<Action>() { new RotateImageAction(angle: 45), new BlurImageAction(blur: 0.5), new ScaleImageAction(x: 2.0, y: 2.0) image.executeactions(actions);

Mediator Pattern Design an intermediary to decouple many peers, which promotes loose coupling by keeping objects from referring to each other explicitly. Example: ViewController in between code and the view it controls. public class Mediator { public void Push(); public void Pop(); public class Producer { private Mediator mediator; public void Produce() { mediator.push(new Item()); public class Consumer { private Mediator mediator; public void Consume() { Item item = mediator.pop();

Memento Pattern Allow an object to restore itself back to its previous state without violating encapsulation (e.g. undo or rollback operations). The memento is opaque to the outside, and must not operated on. public class ButtonWidget { private ButtonState currentstate; public void SetState(OpaqueHandle state) { this.currentstate = (ButtonState)state; public OpaqueHandle GetState() {

State Pattern Allow an object to alter its behavior when its internal state changes. Can be implemented as a delagate. Simply an Object Oriented state machine (possibly using the Visitor pattern to delegate). Related: Strategy class CircleState : IShapeState { public Draw(Shape shape) { class Shape { private IShapeState shapestate; public void Draw() { this.shapestate.draw(this); // Also using visitor pattern here shape.setstate(circlestate); shape.draw();

Strategy Pattern Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from the clients that use it. Uses interfaces. Related to Template Method. interface IImageEncoder { public Buffer encode(buffer rawdata) { class Image { private Buffer imagedata; public Save(string filename, IImageEncoder encoder) { IO.Open(fileName).Write(encoder.encode(this.imageData)); image.save( image.png, new PngEncoder());

Pattern Similarities The strategy pattern allows you to change the implementation of something used at runtime. The Decorator pattern allows you augment (or add) existing functionality with additional functionality at run time. Strategy uses interfaces, while Template Method uses abstract classes. The difference between Strategy and State is in binding times: Strategy is a bind-once pattern, whereas State is more dynamic. A change in the state causes it to select from its "palette" of Strategy objects. Iterator and Adapter are similar, but Adapter is a structural pattern while Iterator is a behavioral pattern. The Facade only exposes the existing functionality from a different perspective. The Mediator "adds" functionality because it combines different existing functionality to create a new one.

Pattern Similarities Bridge: ( A structural pattern) Bridge pattern decouples abstraction and implementation and allows both to vary independently. Use this pattern when : 1. Abstractions and implementations have not been decided at compile time 2. Abstractions and implementations should be changed independently 3. Changes in implementation of abstraction should not affect caller application 4. Client should be insulated from implementation details. Strategy: ( Behavioural pattern) Strategy patterns enable you to switch between multiple algorithms from a family of algorithms at run time. Use Strategy pattern when : 1. Multiple versions of algorithms are required 2. The behaviour of class has to be changed dynamically at run time 3. Avoid conditional statements

Dependency Injection Pass around objects instead of using singletons or direct access to prevent tight coupling. Implements inversion of control for resolving dependencies. public class Foo { public void dowork() { EventManager.Instance.EventQueue(); // Accesses concrete class EventManager directly Using Dependency Injection: public class Foo { IEventManager eventmanager; public void dowork() { eventmanager.eventqueue(); // Not coupled (using interface), easier to unit test

FIN