Aniruddha Chakrabarti

Slides:



Advertisements
Similar presentations
Design Patterns based on book of Gang of Four (GoF) Erich Gamma, Richard Helm, Ralph Johnson, and John VlissidesGang of Four (GoF) Elements of Reusable.
Advertisements

GoF State Pattern Aaron Jacobs State(305) Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
Design Patterns Introduction What is a Design Pattern? Why were they developed? Why should we use them? How important are they?
James Tam Introduction To Design Patterns You will learn about design techniques that have been successfully applied to different scenarios.
Design Patterns for Object Oriented systems CSC 515 Ashwin Dandwate.
Design Patterns Yes, they are important Robert Cotton April 23, 2009.
05/26/2004www.indyjug.net1 Indy Java User’s Group June Knowledge Services, Inc.
Fundamentals of Software Development 1Slide 1 Gang of Four The beginnings… The original “patterns” idea was from architecture – there are repeatable patterns.
Introduction to Software Architecture. What is Software Architecture?  It is the body of methods and techniques that help us to manage the complexities.
Design Patterns CS is not simply about programming
James Tam Introduction To Design Patterns You will learn about design techniques that have been successfully applied to different scenarios.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
March R McFadyen1 GoF (Gang of Four): Gamma, Johnson, Helm & Vlissides Book: Design Patterns: Elements of Reusable Object-Oriented Software.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Adapters Presented By Zachary Dea. Definition A pattern found in class diagrams in which you are able to reuse an ‘adaptee’ class by providing a class,
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
What Is a Factory Pattern?.  Factories are classes that create or construct something.  In the case of object-oriented code languages, factories construct.
Builder A Creational Design Pattern A Presentation by Alex Bluhm And.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Implementing Design Patterns Using Java St. Louis Java Special Interest Group Eric M. Burke Object Computing, Inc. Presented on July 9, 1998 (updated July.
An Introduction to Software Architecture
Chapter 1 Object-Oriented Analysis and Design. Disclaimer Slides come from a variety of sources: –Craig Larman-developed slides; author of this classic.
Advanced topics in software engineering CSC532 Term Paper Design Patterns Harpreet Singh Submitted By:-
Copyright © 2002, Systems and Computer Engineering, Carleton University Patterns.ppt * Object-Oriented Software Development Part 11.
January 12, Introduction to Design Patterns Tim Burke References: –Gamma, Erich, et. al. (AKA, The Gang of Four). Design Patterns: Elements of Reusable.
Creational Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
CS 325: Software Engineering February 12, 2015 Applying Responsibility-Assignment Patterns Design Patterns Situation-Specific Patterns Responsibility-Assignment.
Design Patterns Introduction What is a Design Pattern? Why were they developed? Why should we use them? How important are they?
Design Patterns Introduction to Design Patterns Eriq Muhammad Adams J. Mail : | Blog :
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Mohammed Al-Dhelaan CSci 253 Object Oriented Design Instructor: Brad Taylor 06/02/2009 Factory Method Pattern.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
ECE450S – Software Engineering II
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
05/26/2004www.indyjug.net1 Indy Java User’s Group May Knowledge Services, Inc.
CS 590L – Distributed Component Architecture 02/20/2003Uttara Paingankar1 Design Patterns: Factory Method The factory method defines an interface for creating.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Design Patterns: Elements of Reusable Object- Orientated Software Gamma, Helm, Johnson, Vlissides Presented By: David Williams.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMMING PRACTICES Model View.
Design Patterns in Context ©SoftMoore ConsultingSlide 1.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
1 Lecture Material Design Patterns Visitor Client-Server Factory Singleton.
Patterns in programming
Design Patterns Source: “Design Patterns”, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides And Created.
Design Patterns: MORE Examples
Strategy Design Pattern
The Object-Oriented Thought Process Chapter 15
MPCS – Advanced java Programming
Introduction to Design Patterns
Low Budget Productions, LLC
Factory Patterns 1.
Design Patterns Introduction
Design Patterns.
Presented by Igor Ivković
08/15/09 Design Patterns James Brucker.
DESIGNING YOUR SYSTEM.
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
DESIGN PATTERNS : Introduction
Advanced ProgramMING Practices
Design Patterns Imran Rashid CTO at ManiWeber Technologies.
Advanced ProgramMING Practices
Composite Design Pattern By Aravind Reddy Patlola.
Presented by Igor Ivković
Software Design Lecture : 27.
Presentation transcript:

Aniruddha Chakrabarti RedRock Seminar Design Pattern – Factory Patterns Aniruddha Chakrabarti

What is Design Pattern Addresses a recurring design problem that arises in specific design situations and presents a solution to it. Constitutes a set of rules describing how to accomplish certain tasks in software development Focus more on reuse of recurring architectural design themes, while frameworks focus on detailed design and implementation Identify and specify abstractions that are above the level of single classes and instances or of components. (Gamma, Johnson, and Vlissides, 1993) Helps in improving code quality

Little bit of History Began to be recognized more formally in the early ‘90s by Eric Gamma - described patterns incorporated in the GUI app f/w Continued Discussion & meeting lead to publication of parent book – “Design Patterns: Elements of Reusable Software” by Gof (Erich Gamma, Richard Helm, Ralph Johnson, & John Vlissides) in ‘95 Had a powerful impact on S/W Development community Became an all-time bestseller. Describes 23 commonly occurring & generally useful patterns & comments on how and when to apply them. Other useful books were published later One closely related book is The Design Patterns Smalltalk Companion Later books on different language like Java, VB, .net were published

Grouping Design Patterns Creational patterns create objects for you rather than having you instantiate objects directly. Gives program more flexibility in deciding which objects need to be created for a given case Structural patterns help you compose groups of objects into larger structures, such as complex user interfaces or accounting data. Behavioral patterns help you define the communication between objects in your system and how the flow is controlled in a complex program.

Grouping Design Patterns – Examples Creational Structural Behavioral Abstract Factory Adapter Iterator Factory Method Façade Observer Builder Proxy Mediator Singleton Composite Command Prototype Bridge Template Method

Factory Design Patterns Just what their name implies: they are classes that create or construct something. Provide encapsulation of code required to render an instance of abstract class type as an implementation class Provides a simple decision-making class that returns one of several possible subclasses of an abstract base class, depending on the data that are provided. The factory can initialize, pull in data, configure, set state, & perform nearly any other creational operation needed Three different flavors of Factory Design Patterns - Simple Factory Abstract Factory Factory Method

Simple Factory Very popular – could be found again & again Returns an instance of one of several possible classes, depending on the data provided to it. Usually all of the classes it returns have a common parent class and common methods but each of them performs a task differently and is optimized for different kinds of data. Not a GoF patterns, but it serves here as an introduction to the somewhat more subtle Abstract Factory & Factory Method GoF pattern

Simple Factory Class Diagram Two main parts – Factory Class Product Class Factory class renders the Product class Product class contains data or functionality & is part of a series of class types that can be rendered from Factory class

Problem 1 Implementation classes with a common base are created in multiple places No uniformity exists between creational logic .....lives in class FindSuit Suit suit; if(suitType == SuitType.Armani) suit = new Armani(); else if(suitType == SuitType.StripedBusinessSuit) suit = new StripedBusinessSuit(); .....lives in class GetSuit if(suitType == SuitType.PlaidBusinessSuit) suit = new PlaidBusinessSuit(); else if(suitType == SuitType.GolfSuit) suit = new GolfSuit();

Solution 1 Encapsulate the creation and decisional process of which type of the Suit class to create Central place to house the conditional code.

Solution 1 – Code Example public sealed class SuitFactory { public Suit CreateSuit(SuitType suitType) {Suit suit; if(suitType == SuitType.Armani) suit = new Armani(); else if(suitType == SuitType.StripedBusinessSuit) suit = new StripedBusinessSuit(); else if(suitType == SuitType.PlaidBusinessSuit) suit = new PlaidBusinessSuit(); else if(suitType == SuitType.GolfSuit) suit = new GolfSuit(); return suit; } } .....refactored in class FindSuit & GetSuit SuitFactory factory = new SuitFactory(); Suit suit = factory.CreateSuit(SuitType.Armani);

Simple Factory usage in RedRock Encapsulates the logic for instantiating a working implementation of the ILockRequestManager interface Returns Client Version or Sever Version of ILockRequestManager implementaion depending on where the component resides.

Abstract Factory Expands the basic Factory pattern Gives us a way to allow factories with similar methods and access points to be interchangeable.

Abstract Factory Class Diagram Two main components: Abstract Factory Abstract Product. Expands the basic Factory pattern Gives us a way to allow factories with similar methods and access points to be interchangeable.

Abstract Factory usage in .net BCL/FCL DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SqlClient"); DbConnection conn = factory.CreateConnection(); MessageBox.Show(conn.GetType().ToString());

Factory Method Class Diagram

Factory Method used in .net FCL ArrayList al = new ArrayList(); al.Add("asd"); MessageBox.Show(al.GetEnumerator() .GetType().ToString()); Output - Hashtable ht = new Hashtable(); ht.Add("key1","asd"); MessageBox.Show(ht.GetEnumerator() .GetType().ToString()); Output -

Parameterized Factory Method used in .net FCL SymmetricAlgorithm symAlgo = SymmetricAlgorithm.Create(“SHA1"); MessageBox.Show(symAlgo.GetType().ToString()); Output - SymmetricAlgorithm symAlgo = SymmetricAlgorithm.Create(“MD5"); MessageBox.Show(symAlgo.GetType().ToString()); Output -

Resources Website Books Usage of factory Method with in .net FCL/BCL- http://www.ondotnet.com/pub/a/dotnet/2003/08/11/factorypattern.html Design Patterns in C# and VB - http://www.dofactory.com/Patterns/Patterns.aspx Books Design Patterns – GOF Design Patterns – Christpher G Lasater Software Factories – Jack Greenfield and Keith Short

Questions If (Questions == null || Questions.Count == 0) { Thank you; }