SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.

Slides:



Advertisements
Similar presentations
UML (cont.) “The Unified Modeling Language User Guide” by G. Booch, J. Rumbaugh and I. Jacobson ● Classes ● Relationships ● Class diagrams ● Examples.
Advertisements

SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
© 2005 Prentice Hall8-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
GRASP : Designing Objects with Responsibilities
GRASP Principles. How to Design Objects The hard step: moving from analysis to design How to do it? –Design principles (Larman: “patterns”) – an attempt.
1 SAD2 - UML 4 th Lecture Class Diagram in Construction Phase Patterns Case Study Lecturer: Dr Dimitrios Makris
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
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
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
Copyright © Craig Larman All Rights Reserved Responsibility-Driven Design with the GRASP Patterns.
Object-Oriented Design Part 2
GRASP: Designing Objects with Responsibilities
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
What to remember from Chap 13 (Logical architecture)
Peyman Dodangeh Sharif University of Technology Fall 2014.
Software Engineering CS3003 Lecture 4 Code bad smells and refactoring.
Relationships Relationships between objects and between classes.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
OO Design Roshan Chitrakar. Analysis to Design Do the RIGHT thing Do the RIGHT thing Requirement Analysis Requirement Analysis Domain Modeling with addition.
Class Diagram Chapter 21 Applying UML and Patterns Craig Larman.
C++ Inheritance Data Structures & OO Development I 1 Computer Science Dept Va Tech June 2007 © McQuain Generalization versus Abstraction Abstraction:simplify.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Copyright © Craig Larman All Rights Reserved COMP-350 Object-Oriented Analysis and Design GRASP: Designing Objects with Responsibilities Reference:
Chapter 17 Designing with Responsibilities. Fig
CET203 SOFTWARE DEVELOPMENT Session 2A Inheritance (programming in C#)
Overview of Software Project Management Review – Class 5 UML diagrams cont Overview of Software Project Management - Communication CEN 4010 Class 6 – 09/15.
Chapter 9: Relationships Chapter 10: Inheritance and Polymorphism [Arlow and Neustadt, 2005] CS 426 Senior Projects in Computer Science University of Nevada,
General Principles in Assigning Responsibilities Responsibilities Responsibility-Driven Design CRC Cards GRASP.
Coming up Which methods are where? – Overriding Calling super’s methods Coupling and cohesion.
Advanced Programming in Java
Modern Programming Tools And Techniques-I
GRASP – Designing Objects with Responsibilities
Object-Oriented Modeling with UML
Chapter 12: Collaboration Diagram - PART2
TK2023 Object-Oriented Software Engineering
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
GRASP : Designing Objects with Responsibilities
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Component-Level Design
Domain Class Diagram Chapter 4 Part 2 pp
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
Software Engineering Lecture 10.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Advanced Programming Behnam Hatami Fall 2017.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
OBJECT ORIENTED ANALYSIS AND DESIGN
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
Chapter 11: Class Diagram
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Chapter 11: Class Diagram
Object Oriented System Design Responsibilities
Presentation transcript:

SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin

Agenda – Lecture 3b Approaches to Design Exercise: smelly Farm. Larman, GRASP. Wirfs-Brock et. al., RDD. Exercise: smelly Farm. Applying GRASP via Refactoring. 12/29/2018 SOEN 343, © P.Chalin,

Generalization Super (or parent) class; subclass (or child). + aa + getAa ( ) Super (or parent) class; subclass (or child). Sub is-a-kind-of Super Means an object of Sub can be used anywhere an object of Super can. Sub inherits properties of Super. An operation (or attribute) in Sub with same signature overrides the operation (attr.) in Super. Sub + getAa ( ) Operation override is one form of polymorphism. 12/29/2018 SOEN 343, © P.Chalin,

Dependency A dependency is a using relationship that states that a change … of one thing may affect another that uses it. A B 12/29/2018 SOEN 343, © P.Chalin,

Association Is a structural relationship. Specifies that objects of one thing are connected to objects of another. Given an association you can navigate from an object of one class to an object of another and vice versa. I.e. bidirectional navigability is implicit. A B 12/29/2018 SOEN 343, © P.Chalin,

Directed Association Given an association you can navigate from an object of one class to an object of another (but not necessarily vice versa). (… an A might be eventually reachable from a B.) A B 12/29/2018 SOEN 343, © P.Chalin,

Directed Association … with (role) names. A - b : B [a..b] A - b B 12/29/2018 SOEN 343, © P.Chalin,

Approaches to Design Larman’s approach (GRASP). Wirfs-Brock et. al. Responsibility-Drive Design (RDD). Both are based on responsibility assignment. I.e. assigning responsibilities to classes / objects. 12/29/2018 SOEN 343, © P.Chalin,

Object Responsibilities A responsibility is an obligation of an object in terms of its behavior. (More on this later) 12/29/2018 SOEN 343, © P.Chalin,

Design: Larman’s Approach Methodology based on Responsibility assignment. GRASP General Responsibility Assignment Software Patterns. Input: Use cases. Domain model. Operation contracts. Larman, Chapter 16. Principles 12/29/2018 SOEN 343, © P.Chalin,

GRASP Information Expert Creator Low Coupling High Cohesion Controller General Responsibility Assignment Software Patterns. Information Expert Creator Low Coupling High Cohesion Controller Polymorphism … 12/29/2018 SOEN 343, © P.Chalin,

Information Expert “… expresses the common ‘intuition’ that objects do things related to the information they have.” Assign the responsibility for “knowing” [something] to the object (class) that has the information necessary to fulfill the responsibility. 12/29/2018 SOEN 343, © P.Chalin,

Creator Assign to class B the responsibility to create an instance of class A if B aggregates A objects. B contains A objects. B records instances of A objects. B closely uses A objects. B has the initializing data that will be passed to A when it is created. 12/29/2018 SOEN 343, © P.Chalin,

Farm Example Exercise Set 3 12/29/2018 SOEN 343, © P.Chalin,

Farm Class Diagram - animals 12/29/2018 SOEN 343, © P.Chalin,

Test Cases package farm.tests; … public class FarmTest extends …{ public void testGetNumLegs() { Farm f = new Farm(); f.add(new Animal("Duck", "Donald")); assertEquals(2, f.getNumLegs()); f.add(new Animal("Dog", "Pluto")); assertEquals(6, f.getNumLegs()); } 12/29/2018 SOEN 343, © P.Chalin,

Animal Class public class Animal { private String name; private String kind; public Animal(String aKind, String aName) { kind = aKind; name = aName; } public String getKind() { return kind; … 12/29/2018 SOEN 343, © P.Chalin,

Farm Class, public int getNumLegs() { int result = 0; Iterator it = animals.iterator(); while(it.hasNext()) { Animal a = (Animal) it.next(); if(a.getKind().equals("Duck")) { result += 2; } else if(a.getKind().equals( "Dog")) { result += 4; } else { // ? } return result; 12/29/2018 SOEN 343, © P.Chalin,

Bad Smell in Farm.getNumLegs()? Can you fix it? Hints: By Information Expert, who should know about the number of legs of Animals, the Farm or … ? Having cascaded if’s (or switch statements) over information from another class is usually a very bad smell in OO. Apply Larman’s GRASP principles of Information Expert and Polymorphism. 12/29/2018 SOEN 343, © P.Chalin,

GRASP: Polymorphism Principle Larman: When related alternatives or behaviors vary be type (class), assign responsibility for the behavior—using polymorphic operations—to the types for which the behavior varies. (This principle was illustrated last week with the Animal hierarchy.) 12/29/2018 SOEN 343, © P.Chalin,

Farm Example, Solution #1 12/29/2018 SOEN 343, © P.Chalin,

Farm Example, Solution #2 12/29/2018 SOEN 343, © P.Chalin,

Practice in Tutorial Apply Larman’s GRASP principles of Information Expert and Polymorphism. 12/29/2018 SOEN 343, © P.Chalin,