Object-Oriented Design Part 2

Slides:



Advertisements
Similar presentations
Object-Oriented Analysis and Design
Advertisements

Object Design Examples with GRASP
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Jan 23, Ron McFadyen1 SSD for a samplePOS Use Case Figure 13.1 Input Events invoke a system operation of the same name same idea as in object-oriented.
Oct 2, Ron McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Pronunciation: -"fi-z&m Function:
Object-Oriented Analysis and Design
Feb R. McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Pronunciation: -"fi-z&m Function:
1 Software Testing and Quality Assurance Lecture 12 - The Testing Perspective (Chapter 2, A Practical Guide to Testing Object-Oriented Software)
Solving the Problem Analysis & Design.
© 2005 Prentice Hall8-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
February Ron McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Pronunciation: -"fi-z&m.
Low Coupling High Cohesion
Object-Oriented Analysis and Design
GRASP : Designing Objects with Responsibilities
Fall 2009ACS-3913 Ron McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Date: 1753 an interpretation.
Object-Oriented Design. From Analysis to Design Analysis Artifacts –Essential use cases What are the problem domain processes? –Conceptual Model What.
Objectives Design Class Diagrams Issues in system design Generalization Review UML papers.
GRASP Design Patterns: Designing Objects with Responsibilities
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
GRASP Pattern Zhen Jiang West Chester University
GRASP Principles. How to Design Objects The hard step: moving from analysis to design How to do it? –Design principles (Larman: “patterns”) – an attempt.
GRASP Patterns Presented By Dr. Shazzad Hosain. Patterns A pattern describes a problem and solution, and given a name. Examples are Singleton, Adapter,
Chapter 18 Object Design Examples with GRASP. Objectives Design use case realizations –A use-case realization describes how a particular use case is realized.
Chapter 17. GRASP General Responsibility Assignment Software Patterns (Principles) OOD: after identifying requirements, create domain model, define responsiblities.
1 Chapter 17 GRASP Design Patterns: Designing Objects with Responsibilities.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
Architecture GRASP Realization of use cases in interaction diagrams Design class diagram Design ( how )
Chapter 7: Object Design Examples with GRASP. Objective Design use case realizations. Apply GRASP to assign responsibilities to classes. Apply UML to.
Chapter 26 GoF Design Patterns. The Adapter Design Pattern.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
BTS430 Systems Analysis and Design using UML Design Patterns.
Chapter 17. Initial Object Design Inputs: requirements meetings various Use Cases – 10% complete Key risks addressed with preliminary programming System.
GRASP: Designing Objects With Responsibilities Chapter 17 Applying UML and Patterns -Craig Larman.
GRASP: Designing Objects With Responsibilities
Object Design Examples with GRASP (Ch. 18)
Sept Ron McFadyen1 Section 10.1 Domain Models Domain Model: a visual representation of conceptual classes or real-world objects in a domain.
17. GRASP—Designing Objects with Responsibilities III CSE5324 Lecture Quiz 17 due at 5 PM Thursday, 8 October 2015.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Chapter 17 GRASP: Designing Objects with Responsibilities. 1CS6359 Fall 2011 John Cole.
Design Patterns. Patterns “Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution.
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
Copyright © Craig Larman All Rights Reserved Responsibility-Driven Design with the GRASP Patterns.
Next Gen POS Example GRASP again. Same Patterns Different Example!
GRASP: Designing Objects with Responsibilities
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
What to remember from Chap 13 (Logical architecture)
Object-Oriented Analysis and Design Mar 9, 2008.
OO Methodology Elaboration Iteration 2 - Design Patterns -
TK2023 Object-Oriented Software Engineering CHAPTER 12 Introduction to Responsibility-Driven Design.
1 By Rick Mercer with help from Object-Oriented Design Heuristics, Arthur Riel Coupling / Cohesion.
OO Design Roshan Chitrakar. Analysis to Design Do the RIGHT thing Do the RIGHT thing Requirement Analysis Requirement Analysis Domain Modeling with addition.
Copyright © Craig Larman All Rights Reserved COMP-350 Object-Oriented Analysis and Design GRASP: Designing Objects with Responsibilities Reference:
GRASP: Designing Objects With Responsibilities
Chapter 17 Designing with Responsibilities. Fig
OO Methodology Elaboration Phase Iteration 1- Part 3.
Design. 2 The Need for Software Blueprints Knowing an object-oriented language and having access to a library is necessary but not sufficient in order.
General Principles in Assigning Responsibilities Responsibilities Responsibility-Driven Design CRC Cards GRASP.
1 Object Oriented Analysis and Design System Events & Contracts.
OO Methodology Elaboration Phase Iteration 1- Part 2.
Object Design Examples with GRASP
GRASP – Designing Objects with Responsibilities
Chapter 12: Collaboration Diagram - PART2
Conception OBJET GRASP Patterns
TK2023 Object-Oriented Software Engineering
Presentation on GRASP Patterns Submitted by
GRASP : Designing Objects with Responsibilities
GRASP Design Patterns: Designing Objects with Responsibilities
Next Gen POS Example GRASP again.
Object Oriented System Design Responsibilities
Presentation transcript:

Object-Oriented Design Part 2

Responsibility-Driven Design Frames object design as deciding How to assign responsibilities to objects How objects should collaborate – What role each each object should play in a collaboration

What is meant by responsibilities An object’s obligations (and thus behavior) Two types: Doing responsibilities, e.g.: – Creating an object – Calculating something – Initiating action on other objects – Coordinating activities among other objects Knowing responsibilities, e.g.: – Knowing about data – Knowing about related objects – Knowing about things it can derive or calculate

Domain Model attributes inspire knowing responsibilities Design Analysis Register knows its IDSale knows its time

What is meant by collaboration? Objects interact (via messages) to fulfill responsibilities Example: Register collaborates with Sale and Payment to process a payment (its responsibility)

Responsibilities vary in granularity “Big” responsibilities may require collaborations of many objects “Small” responsibilities may be fulfilled by a single object

How to assign responsibilities and design collaborations? No mechanical method – Requires expert human judgment! But there’s hope: patterns!

Patterns Repeatable solution for a commonly occurring software problem Codify existing tried-and-true knowledge Provide vocabulary

Point of Sale Example Think of a cashier’s register – Cashier scans or manually enters the price of items – All items sold make up a sale – Payment is received, change is given – A receipt is generated

What object should be responsible for creating a SalesLineItem? POS Design Question

Creator Pattern Assign class B responsibility of creating instances of class A if 1+ of the following: B “contains” A B records A B closely uses A B has initializing data for A – B is an expert with respect to creating A

What object should be responsible for creating a SalesLineItem? The Creator Pattern says that Sale should create SalesLineItem POS Design Question

How a Sale object might create a SalesLineItem object : Register : Sale

What object should be responsible for knowing the grand total of a sale? POS Design Question

Information Expert Pattern Assign a knowing responsibility to the class that has the information necessary to fulfill the responsibility

What object should be responsible for knowing the grand total of a sale? POS Design Question The Information Expert Pattern says that Sale should know the grand total

How Sale might calculate the grand total Sale will need a method for computing the total

How Sale might calculate the grand total Sales will get the subtotal from each SalesLineItem

How Sale might calculate the grand total SalesLineItem will need to get the price from ProductDescription

How Sale might calculate the grand total These three objects collaborate to compute the grand total Each one must fulfill its own set of responsibilities

What class should be responsible for this? POS Design Question Assume we need to create a Payment instance and associate it with a Sale instance

One possible design: Register creates Payment

Another possible design: Sale creates Payment

Which design is better?

Low Coupling Pattern Assign responsibilities so that coupling stays low Coupling: measure of how strongly one element is connected to others has knowledge of others relies on others

Common types of coupling in OO languages Class C is coupled to class D if C has instance variable that refers to D C invokes method/function of D C method parameter or local variable references D C is direct or indirect subclass of D C implements interface D

Problems with high coupling Given class C highly coupled to class D: Changes in D may force changes in C Harder to understand C in isolation Harder to reuse C because of dependencies on D

Which design has lower coupling? Assuming Sale will eventually need to be coupled with Payment First design adds extra coupling between Register and Sale so second design has lower coupling

Critique: Other considerations may override preference toward low coupling Strength of coupling should be balanced against other design considerations Critique: High coupling to stable/pervasive elements is seldom a problem Consider coupling to Java standard libraries

Review of Key OO Concepts Objects/Classes Information Hiding – The ability to protect class contents from external entities – Private/Protected Inheritance – The ability for a class to extend and override functionality of another class – Generalization/Specification Interface – A contract of functionality other classes can implement Polymorphism – The ability to create an entity that has more than one type

Design Advice Inputs for your design – Use Cases – Sequence Diagrams – Prototypes – Dataflow Diagrams – Architecture Diagrams

Best practices Use known design patterns – Creator – Information Expert – More to come on the next class Take advantage of tried-and-true libraries – Don’t reimplement something that’s already been done Ex: Use known encryption libraries, they have been thoroughly tested and much less likely to have bugs

Vision Statement Next week we’ll start Agile Everyone will create a new vision statement with a new topic using the same specification as HW 0 Consider a solution that lends itself to an iterative design These will be due next Monday

What’s next for you? HW 3 is due tomorrow by midnight HW 4 is posted Think about your new vision statements