SlideShare a Scribd company logo
1 of 28
Download to read offline
Computer Engineering Department



    Object Oriented Software
     Modeling and Design
            CE 350
 Abdel-Karim Al-Tamimi, Ph.D.
       altamimi@yu.edu.jo
http://faculty.yu.edu.jo/altamimi

              Al-Tamimi 2011 ©           1
Overview
• Design Patterns
  – Proxy Design Pattern (Structural)
  – Interpreter Design Pattern (Behavioral)
• Anti-Patterns




                    Al-Tamimi 2011 ©          2
Proxy Design Pattern
• Problem: You need to support resource-
  hungry objects, and you do not want to
  instantiate such objects unless and until
  they are actually requested by the client
• Solution: Provide a surrogate or
  placeholder for another object to control
  access to it


                  Al-Tamimi 2011 ©            3
Proxy Design Pattern
• Use an extra level of indirection to support
  distributed, controlled, or
  intelligent access
• Add a wrapper and delegation to protect
  the real component from
  undue complexity



                   Al-Tamimi 2011 ©          4
Proxy Pattern Common Situations
• A virtual proxy is a placeholder for
  “expensive to create” objects. The real
  object is only created when a client first
  requests/accesses the object
• A remote proxy provides a local
  representative for an object that resides in
  a different address space


                   Al-Tamimi 2011 ©              5
Proxy Pattern Common Situations
• A protective proxy controls access to a sensitive master
  object. The “surrogate” object checks that the caller has
  the access permissions required prior to forwarding
  the request
• A smart proxy interposes additional actions when an
  object is accessed. Typical uses include:
   – Counting the number of references to the real object so that it
     can be freed automatically when there are no more references
     (aka smart pointer)
   – Loading a persistent object into memory when it’s
     first referenced
   – Checking that the real object is locked before it is accessed to
     ensure that no other object can change it
                             Al-Tamimi 2011 ©                           6
Proxy Pattern: UML Structure




           Al-Tamimi 2011 ©    7
Proxy Pattern: Example
• The Proxy provides a surrogate or place
  holder to provide access to an object.
• A check or bank draft is a proxy for funds
  in an account.
• A check can be used in place of cash for
  making purchases and ultimately controls
  access to cash in the issuer’s account.


                   Al-Tamimi 2011 ©            8
Proxy Pattern: Example




        Al-Tamimi 2011 ©   9
Proxy Pattern: Implementation
// "Subject"
  abstract class Subject                          Subject
  {
    public abstract void Request();
  }

  // "RealSubject"
  class RealSubject : Subject
  {
    public override void Request()
    {
      Console.WriteLine("Called RealSubject.Request()");
    }
  }




                        Al-Tamimi 2011 ©                    10
Proxy Pattern: Implementation
// "Proxy"
 class Proxy : Subject                        Proxy
 {
   RealSubject realSubject;

     public override void Request()
     {
       // Use 'lazy initialization'
       if (realSubject == null)
       {
         realSubject = new RealSubject();
       }

         realSubject.Request();
     }
 }

                           Al-Tamimi 2011 ©           11
Proxy Pattern: Implementation
                                           Using Proxy Pattern
static void Main()
    {
      // Create proxy and request a service
      Proxy proxy = new Proxy();
      proxy.Request();

    }




                        Al-Tamimi 2011 ©                     12
Interpreter Design Pattern
• Problem: A class of problems occurs repeatedly in a
  well-defined and well-understood domain. If the
  domain were characterized with a “language”, then
  problems could be easily solved with an
  interpretation “engine”
• Solution: Given a language, define a representation
  for its grammar along with an interpreter that uses the
  representation to interpret sentences in the language
• Map a domain to a language, the language to a
  grammar, and the grammar to a hierarchical object-
  oriented design

                        Al-Tamimi 2011 ©                13
Interpreter Pattern: UML Structure




              Al-Tamimi 2011 ©   14
Interpreter Pattern: Example
• The interpreter pattern defines a grammatical
  representation for a language and an interpreter
  to interpret the grammar
• Musicians are examples of Interpreters. The
  pitch of a sound and its duration can be
  represented in musical notation on a staff.
                                               ♫
• This notation provides the language of music.
  Musicians playing the music from the score are
  able to reproduce the original pitch and duration
  of each sound represented.
                     Al-Tamimi 2011 ©              15
Interpreter Pattern: Example




           Al-Tamimi 2011 ©    16
Interpreter Pattern: Implementation
// "AbstractExpression"
  abstract class AbstractExpression                          Expressions
  {
    public abstract void Interpret(Context context);
  }

  // "TerminalExpression"
  class TerminalExpression : AbstractExpression
  {
    public override void Interpret(Context context)
    {
      Console.WriteLine("Called Terminal.Interpret()");
    }
  }

  // "NonterminalExpression"
  class NonterminalExpression : AbstractExpression
  {
    public override void Interpret(Context context)
    {
      Console.WriteLine("Called Nonterminal.Interpret()");
    }
  }
                               Al-Tamimi 2011 ©                        17
Interpreter Pattern: Implementation
static void Main()
{                                                Using Interpreter Pattern
      Context context = new Context();

     // Usually a tree
     ArrayList list = new ArrayList();

     // Populate 'abstract syntax tree'
     list.Add(new TerminalExpression());
     list.Add(new NonterminalExpression());
     list.Add(new TerminalExpression());
     list.Add(new TerminalExpression());

      // Interpret
      foreach (AbstractExpression exp in list)
      {
        exp.Interpret(context);
      }
}
                           Al-Tamimi 2011 ©                           18
Software development anti-patterns

Anti-Patterns


                          Al-Tamimi 2011 ©   19
Anti-Patterns
• An Anti-pattern is a literary form that describes
  a commonly occurring solution to a problem that
  generates decidedly negative consequences
• The Anti-pattern may be the result of a manager
  or developer not knowing any better, not having
  sufficient knowledge or experience in solving a
  particular type of problem, or having applied a
  perfectly good pattern in the wrong context



                     Al-Tamimi 2011 ©            20
Software Development Anti-patterns
• A key goal of development
  Anti-patterns is to describe
  useful forms of software
  refactoring
• Software refactoring is a
  form of code modification,
  used to improve the
  software structure in
  support of subsequent
  extension and long-term
  maintenance.
• In most cases, the goal is to
  transform code without
  impacting correctness
                            Al-Tamimi 2011 ©   21
The Blob
• Procedural-style design
  leads to one object with a
  lion’s share of the
  responsibilities, while
  most other objects only
  hold data or execute
  simple processes.
• The solution includes
  refactoring the design to
  distribute responsibilities
  more uniformly and
  isolating the effect
  of changes.
                          Al-Tamimi 2011 ©   22
The Blob: Solution




      Al-Tamimi 2011 ©   23
Continuous Obsolescence
•   Technology is changing so
    rapidly that developers have
    trouble keeping up with the
    current versions of software
    and finding combinations of
    product releases that
    work together
•   Architects and developers
    should depend upon interfaces
    that are stable or that they
    control. Open systems
    standards give a measure of
    stability to an otherwise
    chaotic technology market.

                             Al-Tamimi 2011 ©   24
Functional Decomposition
• Happens when non-object-oriented
  developers design and implement an
  application in an object-oriented language
• They may tend to make every subroutine a
  class, ignoring class hierarchy altogether
• This is due to: Lack of object-oriented
  understanding, Lack of architecture
  enforcement, and/or specification
  disasters
                  Al-Tamimi 2011 ©         25
Functional Decomposition: Solution

• If the class has a single method, try to
  better model it as part of an existing class
• Attempt to combine several classes into a
  new class that satisfies a design objective
  – You might consider hierarchy
• If the class does not contain state
  information of any kind, consider
  rewriting it as a function
  – Or use singleton pattern
                    Al-Tamimi 2011 ©             26
Functional Decomposition: Example




             Al-Tamimi 2011 ©       27
Resources
• http://sourcemaking.com/design_patterns




                 Al-Tamimi 2011 ©      28

More Related Content

What's hot

Object-Oriented Analysis & Design (OOAD) Domain Modeling Introduction
  Object-Oriented Analysis & Design (OOAD)  Domain Modeling Introduction  Object-Oriented Analysis & Design (OOAD)  Domain Modeling Introduction
Object-Oriented Analysis & Design (OOAD) Domain Modeling IntroductionDang Tuan
 
agent uml الوكيل باستخدام لغة النمذجة الموحدة
  agent uml الوكيل باستخدام لغة النمذجة الموحدة  agent uml الوكيل باستخدام لغة النمذجة الموحدة
agent uml الوكيل باستخدام لغة النمذجة الموحدةMohamed Elagnaf
 
Extending UML for Agents
Extending UML for AgentsExtending UML for Agents
Extending UML for AgentsMohamed Elagnaf
 
Lecture-03 Introduction to UML
Lecture-03 Introduction to UMLLecture-03 Introduction to UML
Lecture-03 Introduction to UMLartgreen
 
Darshan sem4 140703_ooad_2014 (diagrams)
Darshan sem4 140703_ooad_2014 (diagrams)Darshan sem4 140703_ooad_2014 (diagrams)
Darshan sem4 140703_ooad_2014 (diagrams)Gajeshwar Bahekar
 
UML Diagrams- Unified Modeling Language Introduction
UML Diagrams- Unified Modeling Language IntroductionUML Diagrams- Unified Modeling Language Introduction
UML Diagrams- Unified Modeling Language IntroductionRamakant Soni
 
Uml Omg Fundamental Certification 1
Uml Omg Fundamental Certification 1Uml Omg Fundamental Certification 1
Uml Omg Fundamental Certification 1Ricardo Quintero
 
Unified modelling language (UML)
Unified modelling language (UML)Unified modelling language (UML)
Unified modelling language (UML)Hirra Sultan
 
Elaboration and domain model
Elaboration and domain modelElaboration and domain model
Elaboration and domain modelVignesh Saravanan
 
Object Oriented Analysis Design using UML
Object Oriented Analysis Design using UMLObject Oriented Analysis Design using UML
Object Oriented Analysis Design using UMLAjit Nayak
 
Uml(unified modeling language) Homework Help
Uml(unified modeling language) Homework HelpUml(unified modeling language) Homework Help
Uml(unified modeling language) Homework HelpSteve Nash
 

What's hot (20)

Object-Oriented Analysis & Design (OOAD) Domain Modeling Introduction
  Object-Oriented Analysis & Design (OOAD)  Domain Modeling Introduction  Object-Oriented Analysis & Design (OOAD)  Domain Modeling Introduction
Object-Oriented Analysis & Design (OOAD) Domain Modeling Introduction
 
agent uml الوكيل باستخدام لغة النمذجة الموحدة
  agent uml الوكيل باستخدام لغة النمذجة الموحدة  agent uml الوكيل باستخدام لغة النمذجة الموحدة
agent uml الوكيل باستخدام لغة النمذجة الموحدة
 
Extending UML for Agents
Extending UML for AgentsExtending UML for Agents
Extending UML for Agents
 
Lecture-03 Introduction to UML
Lecture-03 Introduction to UMLLecture-03 Introduction to UML
Lecture-03 Introduction to UML
 
Darshan sem4 140703_ooad_2014 (diagrams)
Darshan sem4 140703_ooad_2014 (diagrams)Darshan sem4 140703_ooad_2014 (diagrams)
Darshan sem4 140703_ooad_2014 (diagrams)
 
UML Diagrams- Unified Modeling Language Introduction
UML Diagrams- Unified Modeling Language IntroductionUML Diagrams- Unified Modeling Language Introduction
UML Diagrams- Unified Modeling Language Introduction
 
Agent uml
Agent umlAgent uml
Agent uml
 
Unified Modeling Language
Unified Modeling LanguageUnified Modeling Language
Unified Modeling Language
 
UML Diagrams
UML DiagramsUML Diagrams
UML Diagrams
 
Unified Modeling Language
Unified Modeling LanguageUnified Modeling Language
Unified Modeling Language
 
Uml Omg Fundamental Certification 1
Uml Omg Fundamental Certification 1Uml Omg Fundamental Certification 1
Uml Omg Fundamental Certification 1
 
Chapter 7 Use Case Model
Chapter 7 Use Case ModelChapter 7 Use Case Model
Chapter 7 Use Case Model
 
Unified modelling language (UML)
Unified modelling language (UML)Unified modelling language (UML)
Unified modelling language (UML)
 
Uml
UmlUml
Uml
 
Elaboration and domain model
Elaboration and domain modelElaboration and domain model
Elaboration and domain model
 
Object Oriented Analysis Design using UML
Object Oriented Analysis Design using UMLObject Oriented Analysis Design using UML
Object Oriented Analysis Design using UML
 
Use case model
Use case modelUse case model
Use case model
 
Uml(unified modeling language) Homework Help
Uml(unified modeling language) Homework HelpUml(unified modeling language) Homework Help
Uml(unified modeling language) Homework Help
 
Case study-the next gen pos
Case study-the next gen posCase study-the next gen pos
Case study-the next gen pos
 
UML Modeling in Java
UML Modeling in JavaUML Modeling in Java
UML Modeling in Java
 

Viewers also liked

Lecture08 examples
Lecture08 examplesLecture08 examples
Lecture08 examplesartgreen
 
Ce350 class project_spring2011_v1.5
Ce350 class project_spring2011_v1.5Ce350 class project_spring2011_v1.5
Ce350 class project_spring2011_v1.5artgreen
 
Lecture04- Use Case Diagrams
Lecture04- Use Case DiagramsLecture04- Use Case Diagrams
Lecture04- Use Case Diagramsartgreen
 
Service Analysis And Design
Service Analysis And DesignService Analysis And Design
Service Analysis And DesignRody Middelkoop
 
Online Loan Management System
Online Loan Management SystemOnline Loan Management System
Online Loan Management SystemSoban Ahmad
 
BIT (UCSC) Final Year Project - Microfinance Loan Management System
BIT (UCSC) Final Year Project - Microfinance Loan Management SystemBIT (UCSC) Final Year Project - Microfinance Loan Management System
BIT (UCSC) Final Year Project - Microfinance Loan Management SystemThiwanka Makumburage
 
Service Oriented Architecture
Service Oriented ArchitectureService Oriented Architecture
Service Oriented ArchitectureRobert Sim
 
Use Case Model
Use Case ModelUse Case Model
Use Case ModelAli Nguyen
 

Viewers also liked (12)

Lecture08 examples
Lecture08 examplesLecture08 examples
Lecture08 examples
 
Lecture06
Lecture06Lecture06
Lecture06
 
Lecture05
Lecture05Lecture05
Lecture05
 
Ce350 class project_spring2011_v1.5
Ce350 class project_spring2011_v1.5Ce350 class project_spring2011_v1.5
Ce350 class project_spring2011_v1.5
 
Lecture04- Use Case Diagrams
Lecture04- Use Case DiagramsLecture04- Use Case Diagrams
Lecture04- Use Case Diagrams
 
Service Analysis And Design
Service Analysis And DesignService Analysis And Design
Service Analysis And Design
 
Soa chapter 5
Soa chapter 5Soa chapter 5
Soa chapter 5
 
Online Loan Management System
Online Loan Management SystemOnline Loan Management System
Online Loan Management System
 
BIT (UCSC) Final Year Project - Microfinance Loan Management System
BIT (UCSC) Final Year Project - Microfinance Loan Management SystemBIT (UCSC) Final Year Project - Microfinance Loan Management System
BIT (UCSC) Final Year Project - Microfinance Loan Management System
 
SOA Unit I
SOA Unit ISOA Unit I
SOA Unit I
 
Service Oriented Architecture
Service Oriented ArchitectureService Oriented Architecture
Service Oriented Architecture
 
Use Case Model
Use Case ModelUse Case Model
Use Case Model
 

Similar to Lecture12

.net Based Component Technologies
.net Based Component Technologies.net Based Component Technologies
.net Based Component Technologiesprakashk453625
 
Android coding guide lines
Android coding guide linesAndroid coding guide lines
Android coding guide lineslokeshG38
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)stanbridge
 
Creational Design Patterns.pptx
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptxSachin Patidar
 
Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)Sameer Rathoud
 
Evolution of Patterns
Evolution of PatternsEvolution of Patterns
Evolution of PatternsChris Eargle
 
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSergey Aganezov
 
Domain-Driven Design
Domain-Driven DesignDomain-Driven Design
Domain-Driven DesignBradley Holt
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview QuestionsSyed Shahul
 
Hibernate reference1
Hibernate reference1Hibernate reference1
Hibernate reference1chandra mouli
 
Hibernate interview questions
Hibernate interview questionsHibernate interview questions
Hibernate interview questionsvenkata52
 
Using Alf with Cameo Simulation Toolkit - Part 1: Basics
Using Alf with Cameo Simulation Toolkit - Part 1: BasicsUsing Alf with Cameo Simulation Toolkit - Part 1: Basics
Using Alf with Cameo Simulation Toolkit - Part 1: BasicsEd Seidewitz
 
Design patterns - Proxy & Composite
Design patterns - Proxy & CompositeDesign patterns - Proxy & Composite
Design patterns - Proxy & CompositeSarath C
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patternspradeepkothiyal
 

Similar to Lecture12 (20)

.net Based Component Technologies
.net Based Component Technologies.net Based Component Technologies
.net Based Component Technologies
 
Clarity in Documentation
Clarity in DocumentationClarity in Documentation
Clarity in Documentation
 
Design_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.pptDesign_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.ppt
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Android coding guide lines
Android coding guide linesAndroid coding guide lines
Android coding guide lines
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
 
Onion (clean) architecture
Onion (clean) architectureOnion (clean) architecture
Onion (clean) architecture
 
Oop.pptx
Oop.pptxOop.pptx
Oop.pptx
 
Creational Design Patterns.pptx
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptx
 
Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)
 
Evolution of Patterns
Evolution of PatternsEvolution of Patterns
Evolution of Patterns
 
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural Patterns
 
Domain-Driven Design
Domain-Driven DesignDomain-Driven Design
Domain-Driven Design
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
 
Hibernate reference1
Hibernate reference1Hibernate reference1
Hibernate reference1
 
Hibernate interview questions
Hibernate interview questionsHibernate interview questions
Hibernate interview questions
 
Using Alf with Cameo Simulation Toolkit - Part 1: Basics
Using Alf with Cameo Simulation Toolkit - Part 1: BasicsUsing Alf with Cameo Simulation Toolkit - Part 1: Basics
Using Alf with Cameo Simulation Toolkit - Part 1: Basics
 
Design patterns - Proxy & Composite
Design patterns - Proxy & CompositeDesign patterns - Proxy & Composite
Design patterns - Proxy & Composite
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patterns
 

More from artgreen

Lecture07 examples
Lecture07 examplesLecture07 examples
Lecture07 examplesartgreen
 
Lecture04- Use Case Diagrams
Lecture04- Use Case DiagramsLecture04- Use Case Diagrams
Lecture04- Use Case Diagramsartgreen
 

More from artgreen (8)

Lecture10
Lecture10Lecture10
Lecture10
 
Lecture09
Lecture09Lecture09
Lecture09
 
Lecture09
Lecture09Lecture09
Lecture09
 
Lecture08
Lecture08Lecture08
Lecture08
 
Lecture07 examples
Lecture07 examplesLecture07 examples
Lecture07 examples
 
Lecture05
Lecture05Lecture05
Lecture05
 
Lecture05
Lecture05Lecture05
Lecture05
 
Lecture04- Use Case Diagrams
Lecture04- Use Case DiagramsLecture04- Use Case Diagrams
Lecture04- Use Case Diagrams
 

Recently uploaded

ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 

Recently uploaded (20)

Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 

Lecture12

  • 1. Computer Engineering Department Object Oriented Software Modeling and Design CE 350 Abdel-Karim Al-Tamimi, Ph.D. altamimi@yu.edu.jo http://faculty.yu.edu.jo/altamimi Al-Tamimi 2011 © 1
  • 2. Overview • Design Patterns – Proxy Design Pattern (Structural) – Interpreter Design Pattern (Behavioral) • Anti-Patterns Al-Tamimi 2011 © 2
  • 3. Proxy Design Pattern • Problem: You need to support resource- hungry objects, and you do not want to instantiate such objects unless and until they are actually requested by the client • Solution: Provide a surrogate or placeholder for another object to control access to it Al-Tamimi 2011 © 3
  • 4. Proxy Design Pattern • Use an extra level of indirection to support distributed, controlled, or intelligent access • Add a wrapper and delegation to protect the real component from undue complexity Al-Tamimi 2011 © 4
  • 5. Proxy Pattern Common Situations • A virtual proxy is a placeholder for “expensive to create” objects. The real object is only created when a client first requests/accesses the object • A remote proxy provides a local representative for an object that resides in a different address space Al-Tamimi 2011 © 5
  • 6. Proxy Pattern Common Situations • A protective proxy controls access to a sensitive master object. The “surrogate” object checks that the caller has the access permissions required prior to forwarding the request • A smart proxy interposes additional actions when an object is accessed. Typical uses include: – Counting the number of references to the real object so that it can be freed automatically when there are no more references (aka smart pointer) – Loading a persistent object into memory when it’s first referenced – Checking that the real object is locked before it is accessed to ensure that no other object can change it Al-Tamimi 2011 © 6
  • 7. Proxy Pattern: UML Structure Al-Tamimi 2011 © 7
  • 8. Proxy Pattern: Example • The Proxy provides a surrogate or place holder to provide access to an object. • A check or bank draft is a proxy for funds in an account. • A check can be used in place of cash for making purchases and ultimately controls access to cash in the issuer’s account. Al-Tamimi 2011 © 8
  • 9. Proxy Pattern: Example Al-Tamimi 2011 © 9
  • 10. Proxy Pattern: Implementation // "Subject" abstract class Subject Subject { public abstract void Request(); } // "RealSubject" class RealSubject : Subject { public override void Request() { Console.WriteLine("Called RealSubject.Request()"); } } Al-Tamimi 2011 © 10
  • 11. Proxy Pattern: Implementation // "Proxy" class Proxy : Subject Proxy { RealSubject realSubject; public override void Request() { // Use 'lazy initialization' if (realSubject == null) { realSubject = new RealSubject(); } realSubject.Request(); } } Al-Tamimi 2011 © 11
  • 12. Proxy Pattern: Implementation Using Proxy Pattern static void Main() { // Create proxy and request a service Proxy proxy = new Proxy(); proxy.Request(); } Al-Tamimi 2011 © 12
  • 13. Interpreter Design Pattern • Problem: A class of problems occurs repeatedly in a well-defined and well-understood domain. If the domain were characterized with a “language”, then problems could be easily solved with an interpretation “engine” • Solution: Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language • Map a domain to a language, the language to a grammar, and the grammar to a hierarchical object- oriented design Al-Tamimi 2011 © 13
  • 14. Interpreter Pattern: UML Structure Al-Tamimi 2011 © 14
  • 15. Interpreter Pattern: Example • The interpreter pattern defines a grammatical representation for a language and an interpreter to interpret the grammar • Musicians are examples of Interpreters. The pitch of a sound and its duration can be represented in musical notation on a staff. ♫ • This notation provides the language of music. Musicians playing the music from the score are able to reproduce the original pitch and duration of each sound represented. Al-Tamimi 2011 © 15
  • 16. Interpreter Pattern: Example Al-Tamimi 2011 © 16
  • 17. Interpreter Pattern: Implementation // "AbstractExpression" abstract class AbstractExpression Expressions { public abstract void Interpret(Context context); } // "TerminalExpression" class TerminalExpression : AbstractExpression { public override void Interpret(Context context) { Console.WriteLine("Called Terminal.Interpret()"); } } // "NonterminalExpression" class NonterminalExpression : AbstractExpression { public override void Interpret(Context context) { Console.WriteLine("Called Nonterminal.Interpret()"); } } Al-Tamimi 2011 © 17
  • 18. Interpreter Pattern: Implementation static void Main() { Using Interpreter Pattern Context context = new Context(); // Usually a tree ArrayList list = new ArrayList(); // Populate 'abstract syntax tree' list.Add(new TerminalExpression()); list.Add(new NonterminalExpression()); list.Add(new TerminalExpression()); list.Add(new TerminalExpression()); // Interpret foreach (AbstractExpression exp in list) { exp.Interpret(context); } } Al-Tamimi 2011 © 18
  • 20. Anti-Patterns • An Anti-pattern is a literary form that describes a commonly occurring solution to a problem that generates decidedly negative consequences • The Anti-pattern may be the result of a manager or developer not knowing any better, not having sufficient knowledge or experience in solving a particular type of problem, or having applied a perfectly good pattern in the wrong context Al-Tamimi 2011 © 20
  • 21. Software Development Anti-patterns • A key goal of development Anti-patterns is to describe useful forms of software refactoring • Software refactoring is a form of code modification, used to improve the software structure in support of subsequent extension and long-term maintenance. • In most cases, the goal is to transform code without impacting correctness Al-Tamimi 2011 © 21
  • 22. The Blob • Procedural-style design leads to one object with a lion’s share of the responsibilities, while most other objects only hold data or execute simple processes. • The solution includes refactoring the design to distribute responsibilities more uniformly and isolating the effect of changes. Al-Tamimi 2011 © 22
  • 23. The Blob: Solution Al-Tamimi 2011 © 23
  • 24. Continuous Obsolescence • Technology is changing so rapidly that developers have trouble keeping up with the current versions of software and finding combinations of product releases that work together • Architects and developers should depend upon interfaces that are stable or that they control. Open systems standards give a measure of stability to an otherwise chaotic technology market. Al-Tamimi 2011 © 24
  • 25. Functional Decomposition • Happens when non-object-oriented developers design and implement an application in an object-oriented language • They may tend to make every subroutine a class, ignoring class hierarchy altogether • This is due to: Lack of object-oriented understanding, Lack of architecture enforcement, and/or specification disasters Al-Tamimi 2011 © 25
  • 26. Functional Decomposition: Solution • If the class has a single method, try to better model it as part of an existing class • Attempt to combine several classes into a new class that satisfies a design objective – You might consider hierarchy • If the class does not contain state information of any kind, consider rewriting it as a function – Or use singleton pattern Al-Tamimi 2011 © 26
  • 27. Functional Decomposition: Example Al-Tamimi 2011 © 27