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.

Slides:



Advertisements
Similar presentations
Object-Oriented Analysis and Design
Advertisements

Object Design Examples with GRASP
Chapter 1 Object Oriented Analysis and Design. UML, Patterns, and Object-Oriented Analysis and Design  The essential skills for the creation of well-designed,
GRASP Patterns M Taimoor Khan
Oct 2, Ron McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Pronunciation: -"fi-z&m Function:
Feb R. McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Pronunciation: -"fi-z&m Function:
February Ron McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Pronunciation: -"fi-z&m.
Object-Oriented Software Engineering Practical Software Development using UML and Java Design Patterns Sources: Chapter 6: Using Design Patterns, and Chapter.
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.
Feb 4, Ron McFadyen1 founded on principles of good OO design idea was first put forth by Christopher Alexander (1977) in their work concerning.
GRASP Design Patterns: Designing Objects with Responsibilities
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.
GRASP PATTERNS Information Expert (Expert) Creator Controller © Lethbridge/Laganière 2001 Chapter 6: Using design patterns1.
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.
Chapter 1 Object-Oriented Analysis and Design. Disclaimer Slides come from a variety of sources: –Craig Larman-developed slides; author of this classic.
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 )
1 Ch 18. Object Design Examples With Grasp Objectives Design use case realizations. Apply GRASP to assign responsibilities to classes. Apply UML to illustrate.
Chapter 7: Object Design Examples with GRASP. Objective Design use case realizations. Apply GRASP to assign responsibilities to classes. Apply UML to.
Requirements To Design--Iteratively Chapter 12 Applying UML and Patterns Craig Larman.
Chapter 6: Structured Vs. Object Oriented Analysis and Design.
Object-Oriented Analysis and Design An Introduction.
INFO 620Lecture #61 Information Systems Analysis and Design More Class Modeling; Patterns INFO 620 Glenn Booker.
BTS430 Systems Analysis and Design using UML Design Patterns.
GRASP: Designing Objects With Responsibilities Chapter 17 Applying UML and Patterns -Craig Larman.
GRASP: Designing Objects With Responsibilities
Object-Oriented Analysis and Design Mar 11, 2008.
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
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.
Object-Oriented Design Part 2
Next Gen POS Example GRASP again. Same Patterns Different Example!
GRASP: Designing Objects with Responsibilities
Object-Oriented Analysis and Design Mar 9, 2008.
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.
Domain Model A representation of real-world conceptual classes in a problem domain. The core of object-oriented analysis They are NOT software objects.
Copyright © Craig Larman All Rights Reserved COMP-350 Object-Oriented Analysis and Design GRASP: Designing Objects with Responsibilities Reference:
GRASP: Designing Objects With Responsibilities
References: Applying UML and patterns Craig Larman
OO Methodology Elaboration Phase Iteration 1- Part 3.
Oct 3, Ron McFadyen1 GRASP Patterns 1.Expert 2.Creator 3.Controller 4.Low Coupling 5.High Cohesion.
General Principles in Assigning Responsibilities Responsibilities Responsibility-Driven Design CRC Cards GRASP.
OO Methodology Elaboration Phase Iteration 1- Part 2.
Object Design Examples with GRASP
GRASP – Designing Objects with Responsibilities
TK2023 Object-Oriented Software Engineering
Chapter 12: Collaboration Diagram - PART2
Conception OBJET GRASP Patterns
Chapter 6: Structured Vs. Object Oriented Analysis and Design.
Chapter 5: Object Oriented Analysis and Design
Chapter 1 OBJECT-ORIENTED ANALYSIS AND DESIGN
DESIGN MODEL: USE-CASE REALIZATIONS WITH 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
GRASP (General Responsibility Assignment Software Patterns)
Chapter 6: Structured Vs. Object Oriented Analysis and Design.
Next Gen POS Example GRASP again.
Object Oriented System Design Responsibilities
Presentation transcript:

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 to create object software. In between a nice idea and a working software, there is much more than programming. Analysis and design provide software “blueprints”, illustrated by a modeling language, like the Unified Modeling Language (UML). Blueprints serve as a tool for thought and as a form of communication with others.

3 Object-Oriented Analysis An investigation of the problem (rather than how a solution is defined) During OO analysis, there is an emphasis on finding and describing the objects (or concepts) in the problem domain. – For example, concepts in a Library Information System include Book, and Library.

4 Object-Oriented Design Emphasizes a conceptual solution that fulfils the requirements. Need to define software objects and how they collaborate to fulfil the requirements. – For example, in the Library Information System, a Book software object may have a title attribute and a getChapter method. Designs are implemented in a programming language. – In the example, we will have a Book class in Java.

5 From Design to Implementation Book title print() public class Book { public void print(); private String title; } Book (concept) Analysis investigation of the problem Design logical solution Construction code Domain conceptRepresentation in analysis of concepts Representation in an object-oriented programming language.

Goals of OO design OO design starts by fleshing the class diagrams – Coad & Nicola call this "the continuum of representation principle: use a single underlying representation, from problem domain to OOA to OOD to OOP," i.e., class diagrams – Reworks and adds detail to class diagrams, e.g., attribute types, visibility (public/private), additional constraints – Looks for opportunities for reuse – Addresses performance issues, both for system and users – Designs UI, database, networking, as needed

Four activities of design (Coad) 1) Improve domain analysis: reuse and performance – OOA focuses primarily on the describing problem domain itself – OOD reexamines the domain with an eye to practical concerns – Reuse: factor out common code in abstract classes – Performance tradeoffs: efficiency vs. effectiveness 2) Human interaction: encapsulates user interface – HIC knows how to present data, not how to compute it – Separation of concerns principle: Keep problem domain classes distinct from human interaction classes. Why? – Loose coupling facilitates software reuse and maintenance – An example: the Smalltalk Model-View-Controller framework: model is the problem domain view is the human interface (windows that view the problem domain objects) controller is the mouse or keyboard input

Four activities of design (continued) 3) Task management – Multi ‑ tasking and concurrency considerations – How does separation of concerns apply here? 4) Data management – Storage and retrieval of external data – Database design (relational or object-oriented) – Or database interface (JDBC, CORBA)

9 GRASP * : Designing Objects with Responsibilities * Genenal Responsibility Assignment Software Patterns

10 Responsibilities and Methods The focus of object design is to identify classes and objects, decide what methods belong where and how these objects should interact. Responsibilities are related to the obligations of an object in terms of its behavior. Two types of responsibilities: – Doing: Doing something itself (e.g. creating an object, doing a calculation) Initiating action in other objects. Controlling and coordinating activities in other objects. – Knowing: Knowing about private encapsulated data. Knowing about related objects. Knowing about things it can derive or calculate.

11 Responsibilities and Methods Responsibilities are assigned to classes during object design. For example, we may declare the following: – “a Sale is responsible for creating SalesLineItems” (doing) – “a Sale is responsible for knowing its total” (knowing) Responsibilities related to “knowing” are often inferable from the Domain Model (because of the attributes and associations it illustrates)

12 Responsibilities and Methods The translation of responsibilities into classes and methods is influenced by the granularity of responsibility. – For example, “provide access to relational databases” may involve dozens of classes and hundreds of methods, whereas “create a Sale” may involve only one or few methods. A responsibility is not the same thing as a method, but methods are implemented to fulfill responsibilities. Methods either act alone, or collaborate with other methods and objects.

13 Responsibilities and Interaction Diagrams Within the UML artifacts, a common context where these responsibilities (implemented as methods) are considered is during the creation of interaction diagrams. Sale objects have been given the responsibility to create Payments, handled with the makePayment method. :Sale :Payment makePayment(…) create(…)

14 Patterns We will emphasize principles (expressed in patterns) to guide choices in where to assign responsibilities. A pattern is a named description of a problem and a solution that can be applied to new contexts; it provides advice in how to apply it in varying circumstances. For example, – Pattern name:Information Expert – Problem:What is the most basic principle by which to assign responsibilities to objects? – Solution:Assign a responsibility to the class that has the information needed to fulfil it.

15 Information Expert (or Expert) Problem: what is a general principle of assigning responsibilities to objects? Solution: Assign a responsibility to the information expert - the class that has the information necessary to fulfill the responsibility. In the next example application, who should be responsible for knowing the grand total of a sale? By Information Expert we should look for that class that has the information needed to determine the total.

16 Information Expert (or Expert) It is necessary to know about all the SalesLineItem instances of a sale and the sum of the subtotals. A Sale instance contains these, i.e. it is an information expert for this responsibility. Sale date time 1..* * Described-by Contains Product Specification description price itemID 1 SalesLineItem quantity

17 Information Expert (or Expert) This is a partial interaction diagram. t := getTotal() :Sale

18 Information Expert (or Expert) What information is needed to determine the line item subtotal? – quantity and price. SalesLineItem should determine the subtotal. This means that Sale needs to send getSubtotal() messages to each of the SalesLineItems and sum the results. :SalesLineItem :Sale 1 *: st := getSubtotal() t := getTotal()

19 Information Expert (or Expert) To fulfil the responsibility of knowing and answering its subtotal, a SalesLineItem needs to know the product price. The ProductSpecification is the information expert on answering its price. :SalesLineItem :Sale 1 *: st := getSubtotal() t := getTotal() :ProductSpecification 1.1: p := getPrice()

20 Information Expert (or Expert) To fulfil the responsibility of knowing and answering the sale’s total, three responsibilities were assigned to three design classes The fulfillment of a responsibility often requires information that is spread across different classes of objects. This implies that there are many “partial experts” who will collaborate in the task. Class Responsibility Sale Knows Sale total SalesLineItem Knows line item total ProductSpecification Knows product price

21 Creator Problem: Who should be responsible for creating a new instance of some class? Solution: Assign class B the responsibility to create an instance of class A if one or more of the following is true: 1.B aggregates A objects. 2.B contains A objects. 3.B records instances of A objects. 4.B has the initializing data that will be passed to A when it is created (thus B is an Expert with respect to creating A).

22 Creator In the example application, who should be responsible for creating a SalesLineItem instance? Since a Sale contains many SalesLineItem objects, the Creator pattern suggests that Sale is a good candidate. Sale date time 1..* * Described-by Contains Product Specification description price itemID 1 SalesLineItem quantity

23 Creator This assignment of responsibilities requires that a makeLineItem method be defined in Sale. :Sale :SalesLineItem makeLineItem(quantity) create(quantity)

24 Low Coupling Coupling: it is a measure of how strongly one element is connected to, has knowledge of, or relies upon other elements. A class with high coupling depends on many other classes (libraries, tools). Problems because of a design with high coupling: – Changes in related classes force local changes. – Harder to understand in isolation; need to understand other classes. – Harder to reuse because it requires additional presence of other classes. Problem: How to support low dependency, low change impact and increased reuse? Solution: Assign a responsibility so that coupling remains low.

25 Low Coupling Assume we need to create a Payment instance and associate it with the Sale. What class should be responsible for this? By Creator, Register is a candidate. :Payment :Register:Sale

26 Low Coupling Register could then send an addPayment message to Sale, passing along the new Payment as a parameter. The assignment of responsibilities couples the Register class to knowledge of the Payment class. :Register makePayment() p:Payment :Sale 1: create() 2:addPayment(p) Sale also coupled to knowledge of a Payment.

27 Low Coupling An alternative solution is to create Payment and associate it with the Sale. No coupling between Register and Payment. :Register makePayment() :Sale :Payment 1: makePayment() 1.1. create()

28 Low Coupling Some of the places where coupling occurs: – Attributes: X has an attribute that refers to a Y instance. – Methods: e.g. a parameter or a local variable of type Y is found in a method of X. – Subclasses: X is a subclass of Y. – Types: X implements interface Y. There is no specific measurement for coupling, but in general, classes that are generic and simple to reuse have low coupling. There will always be some coupling among objects, otherwise, there would be no collaboration.

29 High Cohesion Cohesion: it is a measure of how strongly related and focused the responsibilities of an element are. A class with low cohesion does many unrelated activities or does too much work. Problems because of a design with low cohesion: – Hard to understand. – Hard to reuse. – Hard to maintain. – Delicate, affected by change. Problem: How to keep complexity manageable? Solution: Assign a responsibility so that cohesion remains high.

30 High Cohesion Assume we need to create a Payment instance and associate it with Sale. What class should be responsible for this? By Creator, Register is a candidate. Register may become bloated if it is assigned more and more system operations. :Register p:Payment :Sale create() addPayment(p) makePayment()

31 High Cohesion An alternative design delegates the Payment creation responsibility to the Sale, which supports higher cohesion in the Register. This design supports high cohesion and low coupling. :Register:Sale create() makePayment() :Payment makePayment()

32 High Cohesion Scenarios that illustrate varying degrees of functional cohesion 1.Very low cohesion: class responsible for many things in many different areas. – e.g.: a class responsible for interfacing with a data base and remote-procedure-calls. 2.Low cohesion: class responsible for complex task in a functional area. – e.g.: a class responsible for interacting with a relational database.

33 High Cohesion 3.High cohesion: class has moderate responsibility in one functional area and it collaborates with other classes to fulfill a task. – e.g.: a class responsible for one section of interfacing with a data base. Rule of thumb: a class with high cohesion has a relative low number of methods, with highly related functionality, and doesn’t do much work. It collaborates and delegates.

34 Controller Problem: Who should be responsible for handling an input system event? Solution: Assign the responsibility for receiving or handling a system event message to a class representing one of he following choices: – Represents the overall system. – Represents a use case scenario. – A Controller is a non-user interface object that defines the method for the system operation. Note that windows, applets, etc. typically receive events and delegate them to a controller.