Design Class Diagrams http://flic.kr/p/87iHCA.

Slides:



Advertisements
Similar presentations
Object-Oriented Analysis and Design CHAPTERS 15: UML INTERACTION DIAGRAMS 1.
Advertisements

Inheritance Inheritance Reserved word protected Reserved word super
UML – Class Diagrams.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Chapter 16. Fig Fig Note: If Sale references nothing then the only thing it is associated with is what references it Note: association name.
Foundations: Language Mechanisms and Primitive OO Concepts Lecture 3: Introduction to OO Modeling E. Kraemer adapted from K. Stirewalt.
Vocabulary Key Terms polymorphism - Selecting a method among many methods that have the same name. subclass - A class that inherits variables and methods.
Object-Oriented Analysis and Design
Object Oriented Software Development
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
Java Class Syntax CSIS 3701: Advanced Object Oriented Programming.
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
Effective C#, Chapter 1: C# Language Elements Last Updated: Fall 2011.
CET203 SOFTWARE DEVELOPMENT Session 1A Revision of Classes.
Object-Oriented Analysis and Design Feb 25, 2009.
Systems Analysis and Design in a Changing World, 3rd Edition
CS3773 Software Engineering Lecture 04 UML Class Diagram.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 14 Slide 1 Object-oriented Design.
Chapter 16 Applying UML and Patterns Craig Larman
Fall 2010 CS4310 Requirements Engineering A Brief Review of UML & OO Dr. Guoqiang Hu Department of Computer Science UTEP 1.
NJIT UML Class Diagrams Chapter 16 Applying UML and Patterns Craig Larman.
UML The Unified Modeling Language A Practical Introduction Al-Ayham Saleh Aleppo University
Object-Oriented Analysis and Design Feb 11, 2009.
Design Model Lecture p6 T120B pavasario sem.
Object Oriented Analysis: Associations. 2 Object Oriented Modeling BUAD/American University Class Relationships u Classes have relationships between each.
Inheritance. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on: deriving.
Class Diagram Chapter 21 Applying UML and Patterns Craig Larman.
Chapter 16: UML Class Diagrams
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole.
Chapter 16 UML Class Diagrams.
TK2023 Object-Oriented Software Engineering CHAPTER 11 CLASS DIAGRAMS.
Kyung Hee University Class Diagramming Notation OOSD 담당조교 석사과정 이정환.
Unified Modeling Language (UML)
BTS430 Systems Analysis and Design using UML Design Class Diagrams (ref=chapter 16 of Applying UML and Patterns)
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
ABT1/GUT1/KFT1 Task 4 Prep Diagrams for MediaManager Cynthia Lang, PE, MSChE Pubali Banerjee, PhD IT Course Mentors-Java Assessments.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Modeling with UML – Class Diagrams
Chapter 12 – Object-Oriented Design
Unified Modeling Language (UML)
Sachin Malhotra Saurabh Choudhary
Unified Modeling Language
Inheritance ITI1121 Nour El Kadri.
A Review or Brief Introduction
Chapter 5: Structural Modeling
Design Class Diagrams
Object-Oriented Analysis and Design
Chapter 16 UML Class Diagrams.
Unified Modeling Language
OO Domain Modeling With UML Class Diagrams and CRC Cards
Today’s Objectives Define the Problem Domain
UML Class Diagram: class Rectangle
The Object Oriented Approach to Design
Object Oriented Analysis and Design
Requirements To Design In This Iteration
Chapter 20 Object-Oriented Analysis and Design
Advanced Java Programming
CIS 375 Bruce R. Maxim UM-Dearborn
Appendix A Object-Oriented Analysis and Design
Class Diagrams.
Class Diagram.
Domain Modeling.
CIS 375 Bruce R. Maxim UM-Dearborn
Chapter 16 UML Class Diagrams
Object Oriented System Design Class Diagrams
Appendix A Object-Oriented Analysis and Design
Topics OOP Review Inheritance Review Abstract Classes
UML  UML stands for Unified Modeling Language. It is a standard which is mainly used for creating object- oriented, meaningful documentation models for.
Presentation transcript:

Design Class Diagrams http://flic.kr/p/87iHCA

What are you going to learn about today? Design class diagram notation http://flic.kr/p/8JpkTg

Object-Oriented Design “Define software objects and how they collaborate to satisfy their requirements” You need to be able to reason about a design To understand designer’s intent To critique/improve the design

Source code not best medium for reasoning Lots of redundancy and detail irrelevant for some program understanding tasks Especially poor at depicting relationships among classes in OO programs Solution: Use abstract, visual representations— for example, Design Class Diagrams (DCDs)

Let’s learn UML class diagrams by example

Consider this Java class UML public class Airplane { private int speed; public Airplane() { } public void setSpeed(int speed) { this.speed = speed; } public int getSpeed() { return speed;

Based on this UML, how do you model… a class? Java UML public class Airplane { private int speed; public Airplane() { } public void setSpeed(int speed) { this.speed = speed; } public int getSpeed() { return speed; Airplane Box with class name—simple!

Based on this UML, how do you model… instance variables and methods? Java UML Attribute compartment public class Airplane { private int speed; public Airplane() { } public void setSpeed(int speed) { this.speed = speed; } public int getSpeed() { return speed; Airplane speed setSpeed getSpeed Operation compartment

Tip: Sketch classes starting from the upper left Sale Payment Store address

Based on this UML, how do you model… constructors? Java UML Constructor stereotype public class Airplane { private int speed; public Airplane() { } public void setSpeed(int speed) { this.speed = speed; } public int getSpeed() { return speed; Airplane speed <<constructor>> Airplane setSpeed getSpeed

Based on this UML, how do you model… attribute types? Java UML Attribute type public class Airplane { private int speed; public Airplane() { } public void setSpeed(int speed) { this.speed = speed; } public int getSpeed() { return speed; Airplane speed : int <<constructor>> Airplane setSpeed getSpeed

Based on this UML, how do you model… method signatures? Java UML public class Airplane { private int speed; public Airplane() { } public void setSpeed(int speed) { this.speed = speed; } public int getSpeed() { return speed; Airplane speed : int <<constructor>> Airplane() setSpeed(speed : int) getSpeed() : int Parameter list Return type (omit void)

Based on this UML, how do you model… visibility? Java UML public class Airplane { private int speed; public Airplane() { } public void setSpeed(int speed) { this.speed = speed; } public int getSpeed() { return speed; Airplane - speed : int + <<constructor>> Airplane() + setSpeed(speed : int) + getSpeed() : int - means private + means public # means protected

How to model a reference to a class instance? Java UML public class Airport { ... } public class Airplane { private Airport home; private int speed; Airplane - speed : int + <<constructor>> Airplane() + setSpeed(speed : int) + getSpeed() : int

Like this? Java UML Airplane - home : Airport ✖ - speed : int public class Airport { ... } public class Airplane { private Airport home; private int speed; Airplane - home : Airport - speed : int Not like this! ✖ + <<constructor>> Airplane() + setSpeed(speed : int) + getSpeed() : int

Like this—with an association (arrow)! Java UML public class Airport { ... } public class Airplane { private Airport home; private int speed; Airplane - speed : int + <<constructor>> Airplane() + setSpeed(speed : int) + getSpeed() : int * 1 - home Airport

Distinguish between data types and non-data types! Instances of data types are plain old values Examples: integers, strings, dates, dollar amounts No need to distinguish between two instances of the same dollar amount Instances of non-data types have identity Examples: Sale, Register, Airport, City, Employee Even if two employees had the same name and salary, they would still be distinct employee instances In Design Class Diagrams, model attributes as data types associations among non-data types

But what are these things? Airplane - speed : int + <<constructor>> Airplane() + setSpeed(speed : int) + getSpeed() : int * 1 - home Airport

Examples of multiplicities 8 Also common to see 0..*

How many Airplanes per Airport? How many Airports per Airplane? - speed : int + <<constructor>> Airplane() + setSpeed(speed : int) + getSpeed() : int * 1 Airport per Airplane 0 or more Airplanes per Airport 1 - home Airport

Based on this UML, how do you model… inheritance? Java UML public class Airplane { ... } public class Jet extends Airplane { Airplane … … With a triangle arrow Jet … …

Based on this UML, how do you model… interfaces? With a dashed triangle arrow Interface stereotype Public operations only Java UML public interface Flyable { public void fly(); } public class Airplane implements Flyable { public void fly() { ... <<interface>> Flyable + fly() Airplane … + fly()

With these notations, you be able to express the structure of your object-oriented designs

Refinement process: Unfolding the design Design Classes refine Implementation public class Register { private int id; private Sale currentSale; ... } public class Sale { private DateTime time; ... }

Refinement is not mechanical class City { ... protected: string cityName; unsigned population; vector<Airport*> serves; }; class Airport { string airportName; CODE airportCode; ZONE timeZone; vector<City*> serves; One possible refinement class City { ... protected: string cityName; unsigned population; }; class Airport { string airportName; CODE airportCode; ZONE timeZone; multimap<City*, Airport*> cityServes; multimap<Airport*, City*> airportServes; Another possible refinement

A word about agile modeling (quoting Larman) Experienced analysts and modelers know the secret of modeling: Thus, we favor hand-drawn diagrams over typeset ones The purpose of modeling (sketching UML, …) is primarily to understand, not to document. http://flic.kr/p/7SFKjj

Benefits of refinement process Postpones design decisions until ready to make them Manages complexity Less refined designs more abstract http://flic.kr/p/7WYW68

Summary Design as refinement process http://flic.kr/p/YSY3X Summary Design as refinement process Lot o’ class diagram notations and conventions

Now, I’m going to introduce a bunch of new class diagram notations and conventions to help you make your DCDs more expressive (All notations from last time still apply)

Full format of attribute notation Class attr op visibility name : type multiplicity = default {property} Examples:

Full format of attribute notation Class attr op visibility name : type multiplicity = default {property} Examples:

Full format of attribute notation Class attr op visibility name : type multiplicity = default {property} Examples:

Visibility + Public - Private # Protected ~ Package Any class that can see the containing class can see - Private Only containing class can see # Protected Only containing class and its descendants can see ~ Package Only classes within containing package can see

Full format of attribute notation Class attr op visibility name : type multiplicity = default {property} Examples:

Full format of attribute notation Class attr op visibility name : type multiplicity = default {property} Examples:

Full format of attribute notation Class attr op visibility name : type multiplicity = default {property} Examples:

Full format of operation notation Class attr op visibility name (parameters) : return-type {property} Examples:

Full format of operation notation Class attr op visibility name (parameters) : return-type {property} Examples:

Full format of operation notation Class attr op visibility name (parameters) : return-type {property} Examples: Same as with attributes

Full format of operation notation Class attr op visibility name (parameters) : return-type {property} Examples:

Full format of operation notation Class attr op visibility name (parameters) : return-type {property} Examples:

Modeling attributes and associations public class Register { private int id; private Sale currentSale; ... } public class Sale { private DateTime time;

Distinguish between data types and non-data types! Instances of data types are plain old values Examples: integers, strings, dates, dollar amounts No need to distinguish between two instances of the same dollar amount Instances of non-data types have identity Examples: Sale, Register, Airport, City, Employee Even if two employees had the same name and salary, they would still be distinct instances In Design Class Diagrams, model attributes as data types associations among non-data types

Modeling an ordered list Multiplicity Properties: set unordered, unique elements (default) bag unordered, non-unique elements ordered set ordered, unique elements list (or sequence) ordered, non-unique elements

Modeling a method

Omit setter and getter operations from design classes Added noise outweighs value Assume you have them if you need them

Modeling constructors

Generalization implies inheritance Objects of subclass have all attributes and methods of superclass

Modeling dependencies public class Foo { public void doX() { System.runFinalization(); ... } Foo depends on System Model like this

Modeling interfaces An interface is essentially an abstract class with only abstract, public operations (no attributes and no methods)

Three ways to model constraints 1 2 3

Modeling hashes with qualified associations Multiplicities are different than usual: (catalog, ID)  1 description description  1 (catalog, ID) Implies catalog  0..* description Key type If numbers, could be itemID : Integer

Modeling relationships with association classes Each link between a Company object and a Person object is an instance of Employment

Modeling templates Binding notations:

User-defined compartments

Modeling active objects Each instance of Clock has its own thread of control that executes within run() Note the bars