SlideShare una empresa de Scribd logo
1 de 97
DESIGN PATTERNS

       Fahad Ali Shaikh
About Me
• CIS Graduate
• 3+ years experience in software development
• Asp.Net 3.5, Silverlight 3, Drupal
  CMS, Android, CRM
• Currently CRM consultant at Sakonent
• Passionate Technology Trainer
• Wing Chun Kung Fu student
• Google Fahad Ali Shaikh for more 
Agenda
• What are Design Patterns and why should we
  use them?
• Let’s strengthen our OOP.
• Creational Pattern
  – Singleton
  – Factory Pattern
• Behavioral Patterns
  – Strategy Pattern
  – Observer Pattern
Agenda
• Structural Patterns
  – Decorator Pattern
• Architectural Patterns
  – MVC
What are DP and Why DP?
What are DP and Why DP?
• A design pattern is a documented best
  practice or core of a solution that has been
  applied successfully in multiple environments
  to solve a problem that recurs in a specific set
  of situations.

• Patterns address solution to a problem
What are DP and Why DP?


• Focus on solving the MAIN problem rather
  than the small ones
What are DP and Why DP?


• Someone has already done what you want to
  do
What are DP and Why DP?


• A shared language for communicating the
  experience gained in dealing with these
  recurring problems and their solutions
What are DP and Why DP?


• Patterns are discovered not invented
What are DP and Why DP?


• Patterns are used effectively with experience
Design Patterns Categories
Purpose      Design Pattern            Aspects that can vary

Creational    Abstract Factory   Families of product objects
              Singleton            Creation of a single object
              Factory Method     Subclass of object instantiated

Structural     Adapter           Interface to an object

               Facade              Interface to a subsystem
               Flyweight           Storage costs of objects
               Proxy              How an object is accessed
Behavioral    Command             When & how a request is fulfilled
               Iterator          Traversal of elements in an
                                 aggregate
Lets Strengthen Our OOP!
Lets Strengthen Our OOP!
• Tight Encapsulation
• Encapsulation refers to the combining of
  fields and methods together in a class
  such that the methods operate on the
  data, as opposed to users of the class
  accessing the fields directly.
Lets Strengthen Our OOP!
• Loose Coupling
• Coupling is the extent to which one object
  depends on another object to achieve its
  goal.
Lets Strengthen Our OOP!
• Loose Coupling
  –Coupling is the extent to which one
   object depends on another object
   to achieve its goal.
Lets Strengthen Our OOP!
• Loose Coupling

•   public class Address {
•   public String street;
•   public String city;
•   public int zip;
•   }
Lets Strengthen Our OOP!
• Not so Loose Coupling
•   public class Employee {
•   private Address home;
•   public Employee(String street, String city, int zip) {
•   home = new Address();
•   home.street = street;
•   home.city = city;
•   home.zip = zip;
      }
• }
Lets Strengthen Our OOP!

• Loose Coupling
• Encapsulate – Use getters and setters
Lets Strengthen Our OOP!
• High Cohesion
• Cohesion refers to how closely related
  the specific tasks are of an object.
• High cohesion is when an object performs
  a collection of closely related tasks.
Lets Strengthen Our OOP!
• High Cohesion
•   public class Payroll {
•   public void computeEmployeePay() {
•   System.out.println(“Compute pay for employees”);
•   }
•   public void computeEmployeeTaxes() {
•   System.out.println(“Compute taxes for employees”);
•   }
•   public void addNewEmployee(Employee e) {
•   System.out.println(“New employee hired...”);
•   }
•   }
Lets Strengthen Our OOP!
• Composition vs Inheritance
The Strategy Pattern
• Composition vs Inheritance
The Strategy Pattern
• Define a family of
  algorithms, encapsulate each
  one, and make them
  interchangeable.

• Strategy lets the algorithm vary
  independently from clients that use
  it.
The Strategy Pattern
The Strategy Pattern
But now we need ducks to fly
The Strategy Pattern
The Strategy Pattern
The Strategy Pattern
The Strategy Pattern
The Strategy Pattern
The Strategy Pattern
What do you think about this design?
The Strategy Pattern
The Strategy Pattern
The Strategy Pattern
The Strategy Pattern
The Strategy Pattern
The Strategy Pattern
The Strategy Pattern
The Strategy Pattern
The Strategy Pattern
The Singleton Pattern
The Singleton Pattern
• Ensures a class has only one instance

• Provides a single point of reference
The Singleton Pattern – Use When
• There must be exactly one instance of a
  class.

• May provide synchronous access to
  avoid deadlocks.

• Very common in GUI toolkits, to specify
  the connection to the OS/Windowing
  system
The Singleton Pattern - Benefits
• Controls access to a scarce or unique
  resource

• Helps avoid a central application class with
  various global object references

• Subclasses can have different
  implementations as required. Static or
  global references don’t allow this

• Multiple or single instances can be allowed
The Singleton Pattern
public class ClassicSingleton {
     private static ClassicSingleton instance = null;
     protected ClassicSingleton() {
        // exists only to defeat instantiation.
       //should be private and final for performance
     }
     public static ClassicSingleton getInstance() {
       if(instance == null) {
        instance = new ClassicSingleton();
       }
       return instance;
     }
}
The Factory Pattern
The Factory pattern returns an instance of one of several possible
classes depending on the data provided to it.




   Here, x is a base class and classes xy and xz are derived from it.
   The Factory is a class that decides which of these subclasses to
    return depending on the arguments you give it.
   The getClass() method passes in some value abc, and returns
    some instance of the class x. Which one it returns doesn't matter
    to the programmer since they all have the same methods, but
    different implementations.
The Factory Pattern
The Factory pattern returns an instance of one of several possible
classes depending on the data provided to it.




   Here, x is a base class and classes xy and xz are derived from it.
   The Factory is a class that decides which of these subclasses to
    return depending on the arguments you give it.
   The getClass() method passes in some value abc, and returns
    some instance of the class x. Which one it returns doesn't matter
    to the programmer since they all have the same methods, but
    different implementations.
The Factory Pattern
   Suppose we have an entry form and we want to allow the user to enter his
    name either as “firstname lastname” or as “lastname, firstname”.
   Let’s make the assumption that we will always be able to decide the name
    order by whether there is a comma between the last and first name.


class Namer { //a simple class to take a string apart into two names
        protected String last; //store last name here
        protected String first; //store first name here
        public String getFirst() {
                  return first; //return first name
        }
        public String getLast() {
                  return last; //return last name
        }
}
The Factory Pattern
In the FirstFirst class, we assume that everything before the last
space is part of the first name.

class FirstFirst extends Namer {
     public FirstFirst(String s) {
          int i = s.lastIndexOf(" "); //find sep space
          if (i > 0) {
                 first = s.substring(0, i).trim(); //left is first name
                 last =s.substring(i+1).trim(); //right is last name
          } else {
                 first = “” // put all in last name
                 last = s; // if no space
          }
     }
}
The Factory Pattern
In the LastFirst class, we assume that a comma delimits the last
name.

class LastFirst extends Namer { //split last, first
    public LastFirst(String s) {
        int i = s.indexOf(","); //find comma
            if (i > 0) {
                 last = s.substring(0, i).trim(); //left is last name
                 first = s.substring(i + 1).trim(); //right is first name
            } else {
                 last = s; // put all in last name
                 first = ""; // if no comma
            }
      }
}
The Factory Pattern
The Factory class is relatively simple. We just test for the existence
of a comma and then return an instance of one class or the other.

class NameFactory {
      //returns an instance of LastFirst or FirstFirst
      //depending on whether a comma is found
      public Namer getNamer(String entry) {
            int i = entry.indexOf(","); //comma determines name order
            if (i>0)
                   return new LastFirst(entry); //return one class
            else
                   return new FirstFirst(entry); //or the other
      }
}
The Factory Pattern
NameFactory nfactory = new NameFactory();
String sFirstName, sLastName;
….
private void computeName() {
  //send the text to the factory and get a class back
  namer = nfactory.getNamer(entryField.getText());
  //compute the first and last names using the returned class
  sFirstName = namer.getFirst();
  sLastName = namer.getLast();
}
The Factory – When to use
You should consider using a Factory pattern
  when:
 A class can’t anticipate which kind of class of
  objects it must create.
 A class uses its subclasses to specify which
  objects it creates.
 You want to localize the knowledge of which
  class gets created.
Feeling hungry ?
Let’s have a break
The Observer Pattern
 The cases when certain objects need to be
 informed about the changes which occurred
 in other objects and are frequent.
The Observer Pattern
 The cases when certain objects need to be
 informed about the changes which occurred
 in other objects and are frequent.


 Define a one-to-many dependency between
 objects so that when one object changes
 state, all its dependents are notified and
 updated automatically.
The Observer Pattern
• This pattern is a cornerstone of the Model-
  View-Controller architectural design, where
  the Model implements the mechanics of the
  program, and the Views are implemented as
  Observers that are as much uncoupled as
  possible to the Model components.
The Observer Pattern
• The participants classes in the Observer pattern are:
•
  Observable - interface or abstract class defining the operations for
  attaching and de-attaching observers to the client. In the GOF
  book this class/interface is known as Subject.

• ConcreteObservable - concrete Observable class. It maintain the
  state of the observed object and when a change in its state occurs
  it notifies the attached Observers.

• Observer - interface or abstract class defining the operations to be
  used to notify the Observer object.

• ConcreteObserverA, ConcreteObserverB - concrete Observer
  implementations.
The Observer Pattern
•    Observable()
•                 Construct an Observable with zero Observers.
•    void addObserver(Observer o)
•                 Adds an observer to the set of observers for this
     object, provided     that it is not the same as some observer
     already in the set.
•    protected void clearChanged()
•                 Indicates that this object has no longer
     changed, or that it has     already notified all of its
     observers of its most recent change, so    that the hasChanged
     method will now return false.
•    int countObservers()
•                 Returns the number of observers of this
     Observable object.
•    void deleteObserver(Observer o)
•                 Deletes an observer from the set of observers of
     this object.
•    void deleteObservers()
•                 Clears the observer list so that this object no
     longer has any              observers.
The Observer Pattern
•   boolean hasChanged()
•              Tests if this object has changed.
•   void notifyObservers()
•              If this object has changed, as indicated by
    the hasChanged method, then notify all of its
    observers and then call the clearChanged     method to
    indicate that this object has no longer changed.
•   void notifyObservers(Object arg)
•              If this object has changed, as indicated by
    the hasChanged method, then notify all of its
    observers and then call the clearChanged     method to
    indicate that this object has no longer changed.
•   protected void setChanged()
•              Marks this Observable object as having been
    changed; the hasChanged method will now return true.
The Observer Pattern
•   // A Sub-class of Observable: a Clock Timer
•   import java.util.Observable;

•   class ClockTimerModel extends Observable {
      public:
        ClockTimer();
•       int GetHour(){return hour};
        int GetMinute(){return minute};
        int GetSecond(){return second};
•       void tick(){
•        // update internal time-keeping state ……………………
         // The Observable object notifies all its registered observers
         setChanged();
•        notifyObservers();};
•     private:
•       int hour;
•       int minute;
•       int second;
    };

• In green are the changes to be applied to the class to be made an observable
  class.
The Observer Pattern

• public void update(Observable o, Object arg)
•     This method is called whenever the observed
  object is changed. An       application calls an
  Observable object's notifyObservers method to
      have all the object's observers notified of
  the change.
•     Parameters:
•         o   - the observable object.
•         arg - an argument passed to the
  notifyObservers method.
The Observer Pattern
•   // A specific Observer to observe ClockTimerModel:
    DigitalClockView
•   //

•   import java.util.Observer;

•   class DigitalClockView implements Observer {

•        public void update(Observable obs, Object x) {
•         //redraw my clock’s reading
          draw();};
•
         void draw(){
          int hour    = obs.GetHour();
          int minute = obs.GetMinute();
          int second = obs.GetSecond();
•         // draw operation};
•   };
The Observer Pattern
•   public class ObserverDemo extends Object {
•     DigitalClockView clockView;
•     ClockTimerModel clockModel;

•    public ObservDemo() {
•      clockView = new DigitalClockView();
•      clockModel = new ClockTimerModel();
•      clockModel.addObserver(clockView);
•    }
•    public static void main(String[] av) {
•      ObserverDemo me = new ObserverDemo();
•      me.demo();
•    }
•    public void demo() {
•      clockModel.Tick();
•    }
The Decorator Pattern
The Decorator Pattern
First Idea of Implementation
In Reality
Now a beverage can be mixed from different condiment to form
a new
Now, your turns. It is a good solution?
Take some time to complete
What can you criticize about this
inheritance architecture?



Write down your notes to see if you are right…
3 minutes….
Ok time’s up.
The Problem
• The problems of two previous designs
  – we get class explosions, rigid designs,
  – or we add functionality to the base class that
    isn’t appropriate for some of the subclasses.
The Problem Revisited
• If a customer wants a Dark Roast with Mocha
  and Whip
  – Take a DarkRoast object
  – Decorate it with a Mocha object
  – Decorate it with a Whip object
  – Call the cost() method and rely on
  – delegation to add on the condiment costs
Decorator at action
Decorator at action
Decorator at action
Decorator at action
Decorator Pattern Defined
Decorator Pattern for StarBuzz Bevereges
Let’s see some code…
Abstract class for condiments
Concrete base class for beverages
Concrete condiment class
Constructing the new beverages instance
dynamically
Constructing the new beverages instance
dynamically
Model View Controller
MVC
Questions ?

Más contenido relacionado

La actualidad más candente

Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHPLorna Mitchell
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelRamrao Desai
 
Lecture 6 inheritance
Lecture   6 inheritanceLecture   6 inheritance
Lecture 6 inheritancemanish kumar
 
Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threadsDevaKumari Vijay
 
Lecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptLecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptmanish kumar
 
Lecture - 5 Control Statement
Lecture - 5 Control StatementLecture - 5 Control Statement
Lecture - 5 Control Statementmanish kumar
 
Pi j2.3 objects
Pi j2.3 objectsPi j2.3 objects
Pi j2.3 objectsmcollison
 
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysDevaKumari Vijay
 
Java Generics
Java GenericsJava Generics
Java Genericsjeslie
 
Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Abid Kohistani
 
Lecture 4_Java Method-constructor_imp_keywords
Lecture   4_Java Method-constructor_imp_keywordsLecture   4_Java Method-constructor_imp_keywords
Lecture 4_Java Method-constructor_imp_keywordsmanish kumar
 

La actualidad más candente (20)

Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
 
Java02
Java02Java02
Java02
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 
Lecture 6 inheritance
Lecture   6 inheritanceLecture   6 inheritance
Lecture 6 inheritance
 
Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threads
 
Lecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptLecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops concept
 
Core java oop
Core java oopCore java oop
Core java oop
 
Lecture - 5 Control Statement
Lecture - 5 Control StatementLecture - 5 Control Statement
Lecture - 5 Control Statement
 
Core java concepts
Core java conceptsCore java concepts
Core java concepts
 
Java Performance MythBusters
Java Performance MythBustersJava Performance MythBusters
Java Performance MythBusters
 
Java basic
Java basicJava basic
Java basic
 
Pi j2.3 objects
Pi j2.3 objectsPi j2.3 objects
Pi j2.3 objects
 
Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674
 
Scala Paradigms
Scala ParadigmsScala Paradigms
Scala Paradigms
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#
 
Inheritance Mixins & Traits
Inheritance Mixins & TraitsInheritance Mixins & Traits
Inheritance Mixins & Traits
 
Lecture 4_Java Method-constructor_imp_keywords
Lecture   4_Java Method-constructor_imp_keywordsLecture   4_Java Method-constructor_imp_keywords
Lecture 4_Java Method-constructor_imp_keywords
 

Destacado

Data architecture around risk management
Data architecture around risk managementData architecture around risk management
Data architecture around risk managementSuvradeep Rudra
 
Ruby overview
Ruby overviewRuby overview
Ruby overviewAaa Bbb
 
E personal information system
E personal information systemE personal information system
E personal information systemBishar Bn
 
Estrategias competitivas básicas
Estrategias competitivas básicasEstrategias competitivas básicas
Estrategias competitivas básicasLarryJimenez
 
1 introducción a la teoria general de sistemas
1 introducción a la teoria general de sistemas1 introducción a la teoria general de sistemas
1 introducción a la teoria general de sistemasOscar Chevez
 
Elasticity Of Demand Sangam Kumar
Elasticity Of Demand   Sangam KumarElasticity Of Demand   Sangam Kumar
Elasticity Of Demand Sangam KumarSangam Agrawal
 
LAB REPORT DROSOPHILA MELANOGASTER
LAB REPORT DROSOPHILA MELANOGASTERLAB REPORT DROSOPHILA MELANOGASTER
LAB REPORT DROSOPHILA MELANOGASTERsiti sarah
 
Logistica y Cadena de Suministros
Logistica y Cadena de SuministrosLogistica y Cadena de Suministros
Logistica y Cadena de SuministrosGonzalo Lagunes
 
PRESENTACIÓN ACTIVIDAD 2
PRESENTACIÓN ACTIVIDAD 2PRESENTACIÓN ACTIVIDAD 2
PRESENTACIÓN ACTIVIDAD 2juankimo2012
 
Conf fuerza mena
Conf fuerza menaConf fuerza mena
Conf fuerza menajuangares
 
PowerPoint presentation for creating a blog on www.wordpress.com
PowerPoint presentation for creating a blog on www.wordpress.comPowerPoint presentation for creating a blog on www.wordpress.com
PowerPoint presentation for creating a blog on www.wordpress.comSohail Siddiqi
 
Designing Long-Term Policy: Rethinking Transition Management
Designing Long-Term Policy: Rethinking Transition ManagementDesigning Long-Term Policy: Rethinking Transition Management
Designing Long-Term Policy: Rethinking Transition ManagementiBoP Asia
 
Master%20 calidad textos%20del%20curso%20para%20el%20alumno
Master%20 calidad textos%20del%20curso%20para%20el%20alumnoMaster%20 calidad textos%20del%20curso%20para%20el%20alumno
Master%20 calidad textos%20del%20curso%20para%20el%20alumnoLizeth Molina Solis
 
Taller ley de victimas y restitucion de tierras
Taller ley de victimas y restitucion de tierrasTaller ley de victimas y restitucion de tierras
Taller ley de victimas y restitucion de tierrasAutonomo
 
Fundamentos de Pruebas de Software - Capítulo 2
Fundamentos de Pruebas de Software - Capítulo 2Fundamentos de Pruebas de Software - Capítulo 2
Fundamentos de Pruebas de Software - Capítulo 2Professional Testing
 

Destacado (20)

Evaluations
EvaluationsEvaluations
Evaluations
 
Data architecture around risk management
Data architecture around risk managementData architecture around risk management
Data architecture around risk management
 
Ruby overview
Ruby overviewRuby overview
Ruby overview
 
E personal information system
E personal information systemE personal information system
E personal information system
 
Estrategias competitivas básicas
Estrategias competitivas básicasEstrategias competitivas básicas
Estrategias competitivas básicas
 
Sq Lv1a
Sq Lv1aSq Lv1a
Sq Lv1a
 
1 introducción a la teoria general de sistemas
1 introducción a la teoria general de sistemas1 introducción a la teoria general de sistemas
1 introducción a la teoria general de sistemas
 
Nombr
NombrNombr
Nombr
 
Elasticity Of Demand Sangam Kumar
Elasticity Of Demand   Sangam KumarElasticity Of Demand   Sangam Kumar
Elasticity Of Demand Sangam Kumar
 
Mcconnell brief2e
Mcconnell brief2e Mcconnell brief2e
Mcconnell brief2e
 
LAB REPORT DROSOPHILA MELANOGASTER
LAB REPORT DROSOPHILA MELANOGASTERLAB REPORT DROSOPHILA MELANOGASTER
LAB REPORT DROSOPHILA MELANOGASTER
 
Logistica y Cadena de Suministros
Logistica y Cadena de SuministrosLogistica y Cadena de Suministros
Logistica y Cadena de Suministros
 
PRESENTACIÓN ACTIVIDAD 2
PRESENTACIÓN ACTIVIDAD 2PRESENTACIÓN ACTIVIDAD 2
PRESENTACIÓN ACTIVIDAD 2
 
Conf fuerza mena
Conf fuerza menaConf fuerza mena
Conf fuerza mena
 
Cuestionario
CuestionarioCuestionario
Cuestionario
 
PowerPoint presentation for creating a blog on www.wordpress.com
PowerPoint presentation for creating a blog on www.wordpress.comPowerPoint presentation for creating a blog on www.wordpress.com
PowerPoint presentation for creating a blog on www.wordpress.com
 
Designing Long-Term Policy: Rethinking Transition Management
Designing Long-Term Policy: Rethinking Transition ManagementDesigning Long-Term Policy: Rethinking Transition Management
Designing Long-Term Policy: Rethinking Transition Management
 
Master%20 calidad textos%20del%20curso%20para%20el%20alumno
Master%20 calidad textos%20del%20curso%20para%20el%20alumnoMaster%20 calidad textos%20del%20curso%20para%20el%20alumno
Master%20 calidad textos%20del%20curso%20para%20el%20alumno
 
Taller ley de victimas y restitucion de tierras
Taller ley de victimas y restitucion de tierrasTaller ley de victimas y restitucion de tierras
Taller ley de victimas y restitucion de tierras
 
Fundamentos de Pruebas de Software - Capítulo 2
Fundamentos de Pruebas de Software - Capítulo 2Fundamentos de Pruebas de Software - Capítulo 2
Fundamentos de Pruebas de Software - Capítulo 2
 

Similar a Design patterns(red)

Object Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. PolymorphismObject Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. PolymorphismAndiNurkholis1
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshowilias ahmed
 
02-OOP with Java.ppt
02-OOP with Java.ppt02-OOP with Java.ppt
02-OOP with Java.pptEmanAsem4
 
Java design patterns
Java design patternsJava design patterns
Java design patternsShawn Brito
 
Java basic tutorial
Java basic tutorialJava basic tutorial
Java basic tutorialBui Kiet
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: InheritanceTareq Hasan
 
Object-Oriented Programming with C#
Object-Oriented Programming with C#Object-Oriented Programming with C#
Object-Oriented Programming with C#Svetlin Nakov
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHPMichael Peacock
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer ProgrammingInocentshuja Ahmad
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0BG Java EE Course
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.Tarunsingh198
 

Similar a Design patterns(red) (20)

Design patterns
Design patternsDesign patterns
Design patterns
 
Object Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. PolymorphismObject Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. Polymorphism
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
 
02-OOP with Java.ppt
02-OOP with Java.ppt02-OOP with Java.ppt
02-OOP with Java.ppt
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java design patterns
Java design patternsJava design patterns
Java design patterns
 
Java basic tutorial
Java basic tutorialJava basic tutorial
Java basic tutorial
 
Core java
Core javaCore java
Core java
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
java tutorial 3
 java tutorial 3 java tutorial 3
java tutorial 3
 
Java Concepts
Java ConceptsJava Concepts
Java Concepts
 
Object-Oriented Programming with C#
Object-Oriented Programming with C#Object-Oriented Programming with C#
Object-Oriented Programming with C#
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHP
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 

Último

Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Último (20)

Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Design patterns(red)

  • 1. DESIGN PATTERNS Fahad Ali Shaikh
  • 2. About Me • CIS Graduate • 3+ years experience in software development • Asp.Net 3.5, Silverlight 3, Drupal CMS, Android, CRM • Currently CRM consultant at Sakonent • Passionate Technology Trainer • Wing Chun Kung Fu student • Google Fahad Ali Shaikh for more 
  • 3. Agenda • What are Design Patterns and why should we use them? • Let’s strengthen our OOP. • Creational Pattern – Singleton – Factory Pattern • Behavioral Patterns – Strategy Pattern – Observer Pattern
  • 4. Agenda • Structural Patterns – Decorator Pattern • Architectural Patterns – MVC
  • 5. What are DP and Why DP?
  • 6. What are DP and Why DP? • A design pattern is a documented best practice or core of a solution that has been applied successfully in multiple environments to solve a problem that recurs in a specific set of situations. • Patterns address solution to a problem
  • 7. What are DP and Why DP? • Focus on solving the MAIN problem rather than the small ones
  • 8. What are DP and Why DP? • Someone has already done what you want to do
  • 9. What are DP and Why DP? • A shared language for communicating the experience gained in dealing with these recurring problems and their solutions
  • 10. What are DP and Why DP? • Patterns are discovered not invented
  • 11. What are DP and Why DP? • Patterns are used effectively with experience
  • 12. Design Patterns Categories Purpose Design Pattern Aspects that can vary Creational Abstract Factory Families of product objects Singleton Creation of a single object Factory Method Subclass of object instantiated Structural Adapter Interface to an object Facade Interface to a subsystem Flyweight Storage costs of objects Proxy How an object is accessed Behavioral Command When & how a request is fulfilled Iterator Traversal of elements in an aggregate
  • 14. Lets Strengthen Our OOP! • Tight Encapsulation • Encapsulation refers to the combining of fields and methods together in a class such that the methods operate on the data, as opposed to users of the class accessing the fields directly.
  • 15. Lets Strengthen Our OOP! • Loose Coupling • Coupling is the extent to which one object depends on another object to achieve its goal.
  • 16. Lets Strengthen Our OOP! • Loose Coupling –Coupling is the extent to which one object depends on another object to achieve its goal.
  • 17. Lets Strengthen Our OOP! • Loose Coupling • public class Address { • public String street; • public String city; • public int zip; • }
  • 18. Lets Strengthen Our OOP! • Not so Loose Coupling • public class Employee { • private Address home; • public Employee(String street, String city, int zip) { • home = new Address(); • home.street = street; • home.city = city; • home.zip = zip; } • }
  • 19. Lets Strengthen Our OOP! • Loose Coupling • Encapsulate – Use getters and setters
  • 20. Lets Strengthen Our OOP! • High Cohesion • Cohesion refers to how closely related the specific tasks are of an object. • High cohesion is when an object performs a collection of closely related tasks.
  • 21. Lets Strengthen Our OOP! • High Cohesion • public class Payroll { • public void computeEmployeePay() { • System.out.println(“Compute pay for employees”); • } • public void computeEmployeeTaxes() { • System.out.println(“Compute taxes for employees”); • } • public void addNewEmployee(Employee e) { • System.out.println(“New employee hired...”); • } • }
  • 22. Lets Strengthen Our OOP! • Composition vs Inheritance
  • 23. The Strategy Pattern • Composition vs Inheritance
  • 24. The Strategy Pattern • Define a family of algorithms, encapsulate each one, and make them interchangeable. • Strategy lets the algorithm vary independently from clients that use it.
  • 27. But now we need ducks to fly
  • 34. What do you think about this design?
  • 45. The Singleton Pattern • Ensures a class has only one instance • Provides a single point of reference
  • 46. The Singleton Pattern – Use When • There must be exactly one instance of a class. • May provide synchronous access to avoid deadlocks. • Very common in GUI toolkits, to specify the connection to the OS/Windowing system
  • 47. The Singleton Pattern - Benefits • Controls access to a scarce or unique resource • Helps avoid a central application class with various global object references • Subclasses can have different implementations as required. Static or global references don’t allow this • Multiple or single instances can be allowed
  • 48. The Singleton Pattern public class ClassicSingleton { private static ClassicSingleton instance = null; protected ClassicSingleton() { // exists only to defeat instantiation. //should be private and final for performance } public static ClassicSingleton getInstance() { if(instance == null) { instance = new ClassicSingleton(); } return instance; } }
  • 49. The Factory Pattern The Factory pattern returns an instance of one of several possible classes depending on the data provided to it.  Here, x is a base class and classes xy and xz are derived from it.  The Factory is a class that decides which of these subclasses to return depending on the arguments you give it.  The getClass() method passes in some value abc, and returns some instance of the class x. Which one it returns doesn't matter to the programmer since they all have the same methods, but different implementations.
  • 50. The Factory Pattern The Factory pattern returns an instance of one of several possible classes depending on the data provided to it.  Here, x is a base class and classes xy and xz are derived from it.  The Factory is a class that decides which of these subclasses to return depending on the arguments you give it.  The getClass() method passes in some value abc, and returns some instance of the class x. Which one it returns doesn't matter to the programmer since they all have the same methods, but different implementations.
  • 51. The Factory Pattern  Suppose we have an entry form and we want to allow the user to enter his name either as “firstname lastname” or as “lastname, firstname”.  Let’s make the assumption that we will always be able to decide the name order by whether there is a comma between the last and first name. class Namer { //a simple class to take a string apart into two names protected String last; //store last name here protected String first; //store first name here public String getFirst() { return first; //return first name } public String getLast() { return last; //return last name } }
  • 52. The Factory Pattern In the FirstFirst class, we assume that everything before the last space is part of the first name. class FirstFirst extends Namer { public FirstFirst(String s) { int i = s.lastIndexOf(" "); //find sep space if (i > 0) { first = s.substring(0, i).trim(); //left is first name last =s.substring(i+1).trim(); //right is last name } else { first = “” // put all in last name last = s; // if no space } } }
  • 53. The Factory Pattern In the LastFirst class, we assume that a comma delimits the last name. class LastFirst extends Namer { //split last, first public LastFirst(String s) { int i = s.indexOf(","); //find comma if (i > 0) { last = s.substring(0, i).trim(); //left is last name first = s.substring(i + 1).trim(); //right is first name } else { last = s; // put all in last name first = ""; // if no comma } } }
  • 54. The Factory Pattern The Factory class is relatively simple. We just test for the existence of a comma and then return an instance of one class or the other. class NameFactory { //returns an instance of LastFirst or FirstFirst //depending on whether a comma is found public Namer getNamer(String entry) { int i = entry.indexOf(","); //comma determines name order if (i>0) return new LastFirst(entry); //return one class else return new FirstFirst(entry); //or the other } }
  • 55. The Factory Pattern NameFactory nfactory = new NameFactory(); String sFirstName, sLastName; …. private void computeName() { //send the text to the factory and get a class back namer = nfactory.getNamer(entryField.getText()); //compute the first and last names using the returned class sFirstName = namer.getFirst(); sLastName = namer.getLast(); }
  • 56. The Factory – When to use You should consider using a Factory pattern when:  A class can’t anticipate which kind of class of objects it must create.  A class uses its subclasses to specify which objects it creates.  You want to localize the knowledge of which class gets created.
  • 58. Let’s have a break
  • 59. The Observer Pattern  The cases when certain objects need to be informed about the changes which occurred in other objects and are frequent.
  • 60. The Observer Pattern  The cases when certain objects need to be informed about the changes which occurred in other objects and are frequent.  Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
  • 61. The Observer Pattern • This pattern is a cornerstone of the Model- View-Controller architectural design, where the Model implements the mechanics of the program, and the Views are implemented as Observers that are as much uncoupled as possible to the Model components.
  • 62. The Observer Pattern • The participants classes in the Observer pattern are: • Observable - interface or abstract class defining the operations for attaching and de-attaching observers to the client. In the GOF book this class/interface is known as Subject. • ConcreteObservable - concrete Observable class. It maintain the state of the observed object and when a change in its state occurs it notifies the attached Observers. • Observer - interface or abstract class defining the operations to be used to notify the Observer object. • ConcreteObserverA, ConcreteObserverB - concrete Observer implementations.
  • 63. The Observer Pattern • Observable() • Construct an Observable with zero Observers. • void addObserver(Observer o) • Adds an observer to the set of observers for this object, provided that it is not the same as some observer already in the set. • protected void clearChanged() • Indicates that this object has no longer changed, or that it has already notified all of its observers of its most recent change, so that the hasChanged method will now return false. • int countObservers() • Returns the number of observers of this Observable object. • void deleteObserver(Observer o) • Deletes an observer from the set of observers of this object. • void deleteObservers() • Clears the observer list so that this object no longer has any observers.
  • 64. The Observer Pattern • boolean hasChanged() • Tests if this object has changed. • void notifyObservers() • If this object has changed, as indicated by the hasChanged method, then notify all of its observers and then call the clearChanged method to indicate that this object has no longer changed. • void notifyObservers(Object arg) • If this object has changed, as indicated by the hasChanged method, then notify all of its observers and then call the clearChanged method to indicate that this object has no longer changed. • protected void setChanged() • Marks this Observable object as having been changed; the hasChanged method will now return true.
  • 65. The Observer Pattern • // A Sub-class of Observable: a Clock Timer • import java.util.Observable; • class ClockTimerModel extends Observable { public: ClockTimer(); • int GetHour(){return hour}; int GetMinute(){return minute}; int GetSecond(){return second}; • void tick(){ • // update internal time-keeping state …………………… // The Observable object notifies all its registered observers setChanged(); • notifyObservers();}; • private: • int hour; • int minute; • int second; }; • In green are the changes to be applied to the class to be made an observable class.
  • 66. The Observer Pattern • public void update(Observable o, Object arg) • This method is called whenever the observed object is changed. An application calls an Observable object's notifyObservers method to have all the object's observers notified of the change. • Parameters: • o - the observable object. • arg - an argument passed to the notifyObservers method.
  • 67. The Observer Pattern • // A specific Observer to observe ClockTimerModel: DigitalClockView • // • import java.util.Observer; • class DigitalClockView implements Observer { • public void update(Observable obs, Object x) { • //redraw my clock’s reading draw();}; • void draw(){ int hour = obs.GetHour(); int minute = obs.GetMinute(); int second = obs.GetSecond(); • // draw operation}; • };
  • 68. The Observer Pattern • public class ObserverDemo extends Object { • DigitalClockView clockView; • ClockTimerModel clockModel; • public ObservDemo() { • clockView = new DigitalClockView(); • clockModel = new ClockTimerModel(); • clockModel.addObserver(clockView); • } • public static void main(String[] av) { • ObserverDemo me = new ObserverDemo(); • me.demo(); • } • public void demo() { • clockModel.Tick(); • }
  • 71. First Idea of Implementation
  • 73. Now a beverage can be mixed from different condiment to form a new
  • 74.
  • 75.
  • 76. Now, your turns. It is a good solution?
  • 77. Take some time to complete
  • 78. What can you criticize about this inheritance architecture? Write down your notes to see if you are right… 3 minutes….
  • 80.
  • 81. The Problem • The problems of two previous designs – we get class explosions, rigid designs, – or we add functionality to the base class that isn’t appropriate for some of the subclasses.
  • 82. The Problem Revisited • If a customer wants a Dark Roast with Mocha and Whip – Take a DarkRoast object – Decorate it with a Mocha object – Decorate it with a Whip object – Call the cost() method and rely on – delegation to add on the condiment costs
  • 88. Decorator Pattern for StarBuzz Bevereges
  • 89. Let’s see some code…
  • 90. Abstract class for condiments
  • 91. Concrete base class for beverages
  • 93. Constructing the new beverages instance dynamically
  • 94. Constructing the new beverages instance dynamically
  • 96. MVC

Notas del editor

  1. This template can be used as a starter file for presenting training materials in a group setting.SectionsRight-click on a slide to add sections. Sections can help to organize your slides or facilitate collaboration between multiple authors.NotesUse the Notes section for delivery notes or to provide additional details for the audience. View these notes in Presentation View during your presentation. Keep in mind the font size (important for accessibility, visibility, videotaping, and online production)Coordinated colors Pay particular attention to the graphs, charts, and text boxes.Consider that attendees will print in black and white or grayscale. Run a test print to make sure your colors work when printed in pure black and white and grayscale.Graphics, tables, and graphsKeep it simple: If possible, use consistent, non-distracting styles and colors.Label all graphs and tables.
  2. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  3. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  4. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  5. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  6. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  7. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  8. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  9. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  10. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  11. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  12. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  13. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  14. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  15. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  16. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  17. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  18. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  19. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  20. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  21. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  22. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  23. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  24. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  25. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  26. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  27. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  28. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  29. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  30. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  31. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  32. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  33. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  34. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  35. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  36. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  37. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  38. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  39. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  40. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  41. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  42. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  43. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  44. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  45. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  46. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  47. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  48. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  49. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  50. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  51. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  52. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  53. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  54. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  55. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  56. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  57. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  58. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  59. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  60. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  61. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  62. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  63. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  64. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  65. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  66. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  67. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  68. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  69. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  70. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  71. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  72. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  73. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  74. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  75. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  76. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  77. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  78. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  79. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  80. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  81. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  82. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  83. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  84. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  85. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  86. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  87. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  88. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  89. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  90. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  91. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  92. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  93. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  94. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  95. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  96. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  97. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.