Download presentation
Presentation is loading. Please wait.
Published byLaureen O’Brien’ Modified over 8 years ago
1
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2006 Classes and Objects Patrick Bailey Keith Vander Linden Calvin College
2
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 2 Classes and Objects ● Objects are entities that have attributes, behavior and state. ● Classes are sets of objects with common properties and behavior. ● Classes and their interrelationships implement the 3 key elements of object- oriented programming:
3
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 3 Class and Object Diagrams ● Rhapsody combines classes and objects into a single object model diagram. ● Class diagrams: – Are the most common UML diagram – Model classes and the static relationships between them ● Object diagrams: – Model a snapshot of the system objects at some time
4
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 4 Example: Class Diagram Example adapted from Fowler, 2003
5
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 5 Outline ● Class Diagrams – Classes Classes – Relationships Relationships ● Object Diagrams Object Diagrams ● UML Profiles UML Profiles ● Class Diagrams and Code Class Diagrams and Code ● Using Object Model Diagrams Using Object Model Diagrams
6
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 6 Classes ● Classes to model entities in the domain. ● One way to discover classes is to identify noun phrases in domain narratives or descriptions. ● Classes have two features: – Attributes – Operations
7
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 7 Attributes ● Attributes describe properties of classes. ● Syntax: visibility name: type multiplicity = default {property-string}
8
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 8 Classes vs. Attributes ● Not all “entities” should be modeled as classes. ● Classes tend to have: – retained or persistent attributes – multiple attributes – common attributes ● Attributes tend not to have these characteristics.
9
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 9 Operations ● Operations describe services that class objects can perform. ● Operation syntax: visibility name (parameter-list): return-type {property-string} ● Parameter syntax direction name: type = default-value
10
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 10 Relationships ● Relationships link classes together. ● UML supports three types of inter-class relationships: – Association – Generalization – Dependency
11
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 11 Association Associations indicate communication between class objects, with features: – Multiplicity – Directionality – Association Type
12
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 12 Attributes vs. Associations ● Attributes and associations: – both represent structural properties of classes – are presented differently in class diagrams ● Use association to represent relationships between more significant classes. ● Use attributes to represent primitive properties and less significant classes.
13
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 13 Multiplicity ● Association relationships indicate how many objects may fill the property. ● They are specified with min..max on both participants in the relationship.
14
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 14 Directionality ● Associations can be: – Uni-directional – Bi-directional ● Directions can be shown with arrows.
15
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 15 Types of Associations Association relationships can have specialized forms: – Aggregation – Composition
16
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 16 Generalization ● Generalization indicates that all sub-class objects must also be super-class objects. ● Don’t overuse it. ● Distinguish: – Generalization – Classification
17
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 17 Dependency ● A dependency indicates that changes to one class will require changes to another. ● There are a number of different types of dependencies.
18
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 18 Interfaces and Abstract Classes UML provides a short-hand notation for interface dependencies.
19
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 19 Classes and Objects ● UML specifies both: – Class diagrams – Object diagrams ● Object diagrams represent snapshots of the system objects at some time. ● Rhapsody combines the two diagram types into a single Object Model Diagram.
20
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 20 Example Example adapted from Douglass, 2004
21
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 21 UML and Real-Time Systems ● Profiles specialize UML using: – Stereotypes – Tagged values ● The OMG has approved profiles for: – Quality of service – Schedulability, performance and time
22
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 22 Example Example adapted from Douglass, 2004
23
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 23 UML and Data Modeling ● Relational databases are frequently modeled using non-object-oriented languages (e.g., ERDs). ● UML Class diagrams can model OO databases.
24
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 24 Example
25
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 25 Code Generation UML tools help you link UML models with generated code: – Code generation – Reverse engineering – Round-trip engineering
26
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 26 Example
27
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 27 Reverse Engineering ● Reverse engineering UML class diagrams works pretty well for object-oriented code. ● It’s less effective for non-object-oriented code.
28
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 28 Using Object Model Diagrams ● Class diagrams are very common. ● Don’t feel that you must: – Model everything – Use all of the language features ● Don’t forget to build behavioral models.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.