From Design To Code Oct 25, 2006.

Slides:



Advertisements
Similar presentations
Written by: Dr. JJ Shepherd
Advertisements

Chapter 22 Object-Oriented Systems Analysis and Design and UML Systems Analysis and Design Kendall and Kendall Fifth Edition.
Chapter 1 Object-Oriented System Development
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
Copyright W. Howden1 Lecture 6: Design Evaluation and Intro to OO Design Patterns.
© 2005 Prentice Hall8-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
Essentials of interaction diagrams Lecture Outline Collaborations Interaction on collaboration diagrams Sequence diagrams Messages from an object.
NJIT More GRASP Patterns Chapter 22 Applying UML and Patterns Craig Larman Prepared By: Krishnendu Banerjee.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
GRASP : Designing Objects with Responsibilities
Designing with Interaction and Design Class Diagrams Chapters 15 & 16 Applying UML and Patterns Craig Larman With some ideas from students in George Blank’s.
CIT241 Prerequisite Knowledge ◦ Variables ◦ Operators ◦ C++ Syntax ◦ Program Structure ◦ Classes  Basic Structure of a class  Concept of Data Hiding.
Systems Analysis and Design in a Changing World, Fifth Edition
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
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
Chapter 17 GRASP: Designing Objects with Responsibilities. 1CS6359 Fall 2011 John Cole.
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
Systems Analysis and Design in a Changing World, 3rd Edition
Starting Object Design
GRASP: Designing Objects with Responsibilities
TAL7011 – Lecture 4 UML for Architecture Modeling.
What to remember from Chap 13 (Logical architecture)
A Student Guide to Object- Oriented Development Chapter 10 Designing objects and classes.
Interaction Diagram Notation
Object-Oriented Analysis and Design Feb 11, 2009.
1 On To Object Design Chapter 14 Applying UML and Patterns -Craig Larman.
CS 4233 Review Feb February Review2 Outline  Previous Business – My.wpi.edu contains all grades to date for course – Review and contact.
Com S 362: Object-Oriented Analysis and Design Refactoring.
ITEC324 Principle of CS III Chapter 2 (Horstmann’s Book) – Part 1 The Object-Oriented Design Process Hwajung Lee.
Slide 1 Classes and Objects. Slide 2 Messages and Methods.
Com S 362: Object-Oriented Analysis and Design From Design To Code.
Copyright © Craig Larman All Rights Reserved COMP-350 Object-Oriented Analysis and Design GRASP: Designing Objects with Responsibilities Reference:
Com S 362: Object-Oriented Analysis and Design Interaction Diagrams and Responsibility Assignment Oct 23, 2006.
Written by: Dr. JJ Shepherd
Dr. Kivanc DincerCS319 Week 6 - Oct.17,20051 Chapter 14 Onto Object Design Objectives Understand dynamic and static object design modeling. Try agile modeling,
Chapter 2 (Horstmann’s Book) – Part 1 The Object-Oriented Design Process Hwajung Lee.
11 Systems Analysis and Design in a Changing World, Fifth Edition.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Elaboration: Iteration 2. Elaboration: Iteration 2 Basics Iteration 1 ends with : All the software has been tested: The idea in the UP is to do early,
Appendix 3 Object-Oriented Analysis and Design
GRASP – Designing Objects with Responsibilities
Roberta Roth, Alan Dennis, and Barbara Haley Wixom
The Movement To Objects
Systems Analysis and Design
Main issues: • What do we want to build • How do we write this down
Design Class Diagrams
UML Interaction Diagrams
Conception OBJET GRASP Patterns
Chapter 8 Analysis & Modeling
Prepared By Sidra Noureen
Apply Expert, Creator, Controller, Low Coupling, High Cohesion
Class Diagrams Oct 20, 2006.
The Object Oriented Approach to Design
GRASP : Designing Objects with Responsibilities
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
System Sequence Diagrams
Chapter 20 Object-Oriented Analysis and Design
Dynamic Data Structures and Generics
Interaction Diagrams A Lot of UML!
GoF Design Patterns (Ch. 26)
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
COP 3330 Object-oriented Programming in C++
Interfaces.
Chapter 22 Object-Oriented Systems Analysis and Design and UML
GRASP.
ITEC324 Principle of CS III
ITEC324 Principle of CS III
Object Oriented System Design Responsibilities
Presentation transcript:

From Design To Code Oct 25, 2006

Recap: Class Diagrams Class diagrams represent design structure Three parts: name, attribute, operations Visibility, attribute type, multiplicity Association, association multiplicity Generalization i.e. interface impl, subclassing Composition i.e. class A contains class B Applied information hiding, DSM, layering

Recap: Interaction Diagrams Represent functionality Two major parts: Life line boxes (represent life time of an object) Messages between objects (instances) Also looked at some special case notations Instances: parameterized instances, singleton instances, array elements Messages: creation, destruction, conditional messages, mutually exclusive conditional messages, asynchronous messages, polymorphic messages Abstractions: looping, iteration over collection, nesting of frames, decomposition

Today’s Lecture Interaction Diagrams Basics & Notations Responsibility Assignment Principles

Example: Switch-Motor System Scenario: Motor can run, when the Switch state is on Class list: Switch and Motor R1: Store the decision condition R2: Make a decision R3: Run the motor

Class Diagram View Switch Motor -state:bool -switch:Switch 1 -state:bool -switch:Switch switch +getState():bool +run() Class Diagram: three parts – class name, attributes, and operations The first part may also contain stereotypes.

Interaction Diagram View :Motor Lifeline boxes switch:Switch run getState state :Motor represents unnamed instance of class motor switch:Switch represents named instance of class Switch Another examples in the book are paremeterized that are written ArrayList <int>, if you were to use generics in your homework 3. ith element in the array “arr” of type IntArray would be written arr[i]: IntArray In case of a singleton, i.e. a class that only has a single instance in the application domain, we would write a 1 in the top right corner. How would you show creation? Figure 15.10 in book How would you show destruction? Figure 15.11 in book How would you show looping? (Remember from sequence diagram example) Figure 15.12 in book How would you show conditional messages? Figure 15.12 in book How would you show mutually exclusive conditional messages? Figure 15.15 in book How would you show iteration over a collection ? Figure 15.16 in book How would you show nesting of frames? Example in Figure 15.18 shows looping, when a certain condition is true. How would you decompose a larger interaction diagram? Figure 15.19 shows one way. Also, remember from the sequence diagram examples. Essentially the same technique. How would you show polymorphism? Figure 15.21 in book. How would you show asynchronous calls? Figure 15.22 in book.

Switch-Motor: CRC Card View Scenario: Motor can run, when the Switch state is on Class list: Switch and Motor R1: Store the decision condition, R2: Make a decision, and R3: Run the motor Class Name: Switch Subclasses: Super classes: Responsibilities Collaborators Store decision condition Class Name: Motor Subclasses: Super classes: Responsibilities Collaborators Make a decision Switch Run the motor Notice that the Switch is the collaborator of Motor, but not vice versa. Question: What is the coupling relationship in this case?

Class Diagram View Switch Motor -state:bool -switch:Switch 1 -state:bool -switch:Switch switch +getState():bool +run():void void run(){ if(switch.getState()){ /* Make a decision */ /* run the motor */ }

Impact of Change: Multi-State Switch Motor 1 -state:bool -switch:Switch -state:int switch +getState():bool +run():void +getState():int void run(){ if(switch.getState()){ /* Make a decision */ /* run the motor */ } Change: Switch can have more than two states.

Change Escapes Module Boundary Switch Motor 1 -state:bool -switch:Switch -state:int switch +getState():bool +run():void +getState():int void run(){ if(switch.getState()){ /* Make a decision */ /* run the motor */ } Change: Switch can have more than two states. Impact of Change

Information Expert Which class has the necessary information? Example – class list: Switch and Motor R1: Store the decision condition, R2: Make a decision, and R3: Run the motor Class Name: Switch Subclasses: Super classes: Responsibilities Collaborators Store decision Condition Make a decision Class Name: Motor Subclasses: Super classes: Responsibilities Collaborators Run the motor Switch

Improved Class Diagram View Switch Motor 1 -state:bool -switch:Switch switch +isOn():bool +run():void void run(){ if(switch.isOn()){ /* run the motor */ }

Implementation Changes Encapsulated Switch Motor 1 -state:bool -switch:Switch -state:int switch +isOn():bool +run():void +isOn():bool void run(){ if(switch.isOn()){ /* run the motor */ } Change: Switch can have more than two states. Remember: Information Hiding

Example: User-Level Process Management Main scenario: A process will maintain necessary information for it to run such as program counter (PC), reference to program segment (.ps), reference to data segments (.ds), registers (regs) Scenario of interest: functionality to create an identical copy of a process should be provided Class list: process, client R1: store information PC, .ps, .ds. Regs R2: create copy of process

User-Level Process Management : CRC Card View Class list: process, client R1: store information pc, .ps, .ds. regs R2: create copy of process Class Name: Process Subclasses: Super classes: Responsibilities Collaborators Store information pc, .ps, .ds. regs Class Name: Client … Subclasses: Super classes: Responsibilities Collaborators Create copy Process of .pc, .ps, .ds, .regs Spawn another process Notice that the Switch is the collaborator of Motor, but not vice versa. Question: What is the coupling relationship in this case?

Change: Register-based to Stack-based Machine Class list: process, client R1: store information pc, .stack, .top, .ps, .ds. R2: create copy of process Class Name: Process Subclasses: Super classes: Responsibilities Collaborators Store information pc, .stack, .top, .ds. regs Class Name: Client … Subclasses: Super classes: Responsibilities Collaborators Create copy Process of .pc, .ps, .ds, .regs Spawn another process Notice that the Switch is the collaborator of Motor, but not vice versa. Question: What is the coupling relationship in this case? Impact on all clients

Creator: Which class has the initializing data? Class list: process, client R1: store information pc, .ps, .ds. regs R2: create copy of process Class Name: Process Subclasses: Super classes: Responsibilities Collaborators Store information pc, .ps, .ds. regs Create copy of .pc, .ps, .ds, . regs and spawn another process Class Name: Client … Subclasses: Super classes: Responsibilities Collaborators Process Notice that the Switch is the collaborator of Motor, but not vice versa. Question: What is the coupling relationship in this case? Change Impact Encap-sulated

Adding GUI to the Sorting Application Integers (>0) Sorting Algorithm Merge Sort : User Sort Which class should handle the Sort Event? Class Name: UI Subclasses: Super classes: Responsibilities Collaborators Handle Sort SortingApp Event Class Name: SortingApp Subclasses: Super classes: Responsibilities Collaborators Create sorting, ISort, IStorage storage instance etc.

Adding GUI to the Sorting Application SortButton … /addActionListener(ActionListener l) javax.swing.DefaultButtonModel … +addActionListener(ActionListener l) SortingApplication java.awt.event.ActionListener … +actionPerformed(ActionEvent e) storage:IStorage sort:ISort +sort(…):IStorage /actionPerformed(ActionEvent e)

Summary Interaction Diagrams Responsibility Assignment Principles Information Expert Creator Controller Polymorphism Pure Fabrication Indirection Protected Variations Most of these principles are derivative of the information hiding principle that we have studied before. In this lecture: - Understand these principles through examples Understand class and interaction diagrams on the way Relate these principles to information hiding principle Also, show examples of the CRC card process