Essentials of Visual Modeling with UML Module 3: Concepts of...
Transcript of Essentials of Visual Modeling with UML Module 3: Concepts of...
![Page 1: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/1.jpg)
1
IBM Software Group
®
Essentials of Visual Modeling with UML
Module 3: Concepts of Object Orientation
![Page 2: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/2.jpg)
2
Objectives
Describe abstraction, encapsulation, modularity, and hierarchy.Describe the physical structure of a class.Describe the relationship between a class and an object.Define polymorphism and generalization.
![Page 3: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/3.jpg)
3
Where Are We?
What is an object?Four principles of OOWhat is a class?Polymorphism and generalizationOrganizing model elements
![Page 4: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/4.jpg)
4
Truck
Chemical Process
Linked List
What Is an Object?
Informally, an object represents an entity, either physical, conceptual, or software.
Physical entity
Conceptual entity
Software entity
![Page 5: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/5.jpg)
5
A More Formal DefinitionAn object is an entity with a well-defined boundary and identitythat encapsulates stateand behavior.
State is represented by attributes and relationships.Behavior is represented by operations, methods, and state machines. Object
Operations
Attributes
![Page 6: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/6.jpg)
6
An Object Has StateState is a condition or situation during the life of an object, which satisfies some condition, performs some activity, or waits for some event.The state of an object normally changes over time.
Name: J ClarkEmployee ID: 567138Date Hired: July 25, 1991Status: TenuredDiscipline: FinanceMaximum Course Load: 3 classes
Name: J ClarkEmployee ID: 567138HireDate: 07/25/1991Status: TenuredDiscipline: FinanceMaxLoad: 3
Professor Clark
![Page 7: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/7.jpg)
7
An Object Has Behavior
Behavior determines how an object acts and reacts.The visible behavior of an object is modeled by a set of messages it can respond to (operations that the object can perform).
Professor Clark’s behaviorSubmit Final GradesAccept Course OfferingTake SabbaticalMaximum Course Load: 3 classes
SubmitF
inalG
rade
s()
AcceptCourseOffering()
TakeSabbatical()
Professor Clark
SetMaxLoad()
![Page 8: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/8.jpg)
8
An Object Has Identity
Each object has a unique identity, even if the state is identical to that of another object.
Professor “J Clark”teaches Biology
Professor “J Clark”teaches Biology
![Page 9: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/9.jpg)
9
Where Are We?
What is an object?Four principles of OOWhat is a class?Polymorphism and generalizationOrganizing model elements
![Page 10: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/10.jpg)
10
Basic Principles of Object Orientation
Abst
ract
ion
Hier
arch
y
Object Orientation
Enca
psul
atio
n
Modu
larity
![Page 11: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/11.jpg)
11
What Is Abstraction?
The essential characteristics of an entity that distinguishes it from all other kinds of entities. Defines a boundary relative to
the perspective of the viewer. Is not a concrete
manifestation, denotes the ideal essence of something.
![Page 12: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/12.jpg)
12
Example: Abstraction
Student Professor
Course Offering (9:00 a.m., Monday-Wednesday-Friday) Course (e.g. Algebra)
![Page 13: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/13.jpg)
13
What Is Encapsulation?
Improves Resiliency
Hides implementation from clients.Clients depend on interface.
![Page 14: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/14.jpg)
14
Encapsulation Illustrated
Professor Clark needs to be able to teach four classes in the next semester.
SubmitF
inalG
rade
s()
AcceptCourseOffering()
TakeSabbatical()
Professor Clark
SetMaxLoad()
Name: J ClarkEmployee ID: 567138HireDate: 07/25/1991Status: TenuredDiscipline: FinanceMaxLoad:4
SetMaxLoad(4)
![Page 15: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/15.jpg)
15
What Is Modularity?
Breaks up something complex into manageable pieces.Helps people understand complex systems.
![Page 16: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/16.jpg)
16
Example: Modularity
For example, break complex systems into smaller modules. Billing
System
Course Registration System
Course Catalog System
Student Management System
![Page 17: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/17.jpg)
17
What Is Hierarchy?
Decreasing abstraction
Increasingabstraction
Asset
RealEstate
Savings
BankAccount
Checking Stock
Security
Bond
Elements at the same level of the hierarchy should be at the same level of abstraction.
![Page 18: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/18.jpg)
18
Representing Objects in the UML
An object is represented as a rectangle with an underlined name.
J Clark : Professor
: Professor
Named Object
Anonymous Object
Professor J Clark
![Page 19: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/19.jpg)
19
Where Are We?
What is an object?Four principles of OOWhat is a class?Polymorphism and generalizationOrganizing model elements
![Page 20: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/20.jpg)
20
What Is a Class?
A class is a description of a set of objects that share the same attributes, operations,relationships, and semantics.
An object is an instance of a class.A class is an abstraction in that it
Emphasizes relevant characteristics.Suppresses other characteristics.
![Page 21: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/21.jpg)
21
A Sample Class
ClassCourse
PropertiesName
LocationDays offeredCredit hours
Start timeEnd time
BehaviorAdd a student
Delete a studentGet course roster
Determine if it is full
![Page 22: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/22.jpg)
22
Representing Classes in the UML
A class is represented using a rectangle with compartments.
Professor J Clark
Professor- name- employeeID : UniqueId- hireDate- status- discipline- maxLoad
+ submitFinalGrade()+ acceptCourseOffering()+ setMaxLoad()+ takeSabbatical()
![Page 23: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/23.jpg)
23
Class Compartments
A class has three sections:The class nameThe structure (attributes)The behavior (operations)
Professor- name- employeeID : UniqueId- hireDate- status- discipline- maxLoad
+ submitFinalGrade()+ acceptCourseOffering()+ setMaxLoad()+ takeSabbatical()
![Page 24: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/24.jpg)
24
The Relationship between Classes and Objects
A class is an abstract definition of an object.It defines the structure and behavior of each object in the class.It serves as a template for creating objects.
Classes are not collections of objects.
Professor
Professor Meijer
Professor Torpie
Professor Allen
![Page 25: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/25.jpg)
25
What Is an Attribute?
An attribute is a named property of a class that describes the range of values that instances of the property may hold.
A class may have any number of attributes or no attributes at all.
Attributes
Student- name- address- studentID- dateOfBirth
![Page 26: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/26.jpg)
26
Attributes in Classes and Objects
name: D. Hatcheraddress: 456 OakstudentID: 2dateofBirth: 12/11/1969
name: M. Modanoaddress: 123 MainstudentID: 9dateofBirth: 03/10/1967
Class
Objects
Student- name- address- studentID- dateOfBirth
![Page 27: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/27.jpg)
27
What Is an Operation?
A service that can be requested from an object to effect behavior. An operation has a signature, which may restrict the actual parameters that are possible.A class may have any number of operations or none at all.
Operations
Student
+ get tuition()+ add schedule()+ get schedule()+ delete schedule()+ has prerequisites()
![Page 28: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/28.jpg)
28
Where Are We?
What is an object?Four principles of OOWhat is a class?Polymorphism and generalizationOrganizing model elements
![Page 29: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/29.jpg)
29
What Is Polymorphism?
The ability to hide many different implementations behind a single interface.
Manufacturer AManufacturer B Manufacturer C
OO Principle:Encapsulation
![Page 30: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/30.jpg)
30
Example: Polymorphism
Stock Bond Mutual Fund
getCurrentValue()
financialInstrument.getCurrentValue()
getCurrentValue()
getCurrentValue()
![Page 31: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/31.jpg)
31
What Is Generalization?
A relationship among classes where one class shares the structure and/or behavior of one or more classes.Defines a hierarchy of abstractions in which a subclass inherits from one or more superclasses.
Single inheritance.Multiple inheritance.
Is an “is a kind of” relationship.
![Page 32: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/32.jpg)
32
Example: Single Inheritance
One class inherits from another.
CheckingSavings
Superclass (parent)
Subclasses(children)
Generalization Relationship
Ancestor
Ac count- balance- nam e- num ber
+ withdraw()+ createStatem ent()
Descendent
![Page 33: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/33.jpg)
33
Example: Multiple Inheritance
A class can inherit from several other classes.
Use multiple inheritance only when needed and always with caution!
FlyingThing Animal
HorseWolfBirdHelicopterAirplane
Multiple Inheritance
![Page 34: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/34.jpg)
34
What Is Inherited?
Inheritance leverages the similarities among classes.
A subclass inherits its parent’s attributes, operations, and relationships.A subclass may:
Add additional attributes, operations, relationships.Redefine inherited operations. (Use caution!)
Common attributes, operations, and/or relationships are shown at the highest applicable level in the hierarchy.
![Page 35: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/35.jpg)
35
Where Are We?
What is an object?Four principles of OOWhat is a class?Polymorphism and generalizationOrganizing model elements
![Page 36: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/36.jpg)
36
A general purpose mechanism for organizing elements into groups.A model element that can contain other model elements.A package can be used:
To organize the model under development.As a unit of configuration management.
What Is a Package?
University Artifacts
![Page 37: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/37.jpg)
37
A Package Can Contain Classes
The package, University Artifacts, contains one package and five classes.
University Artifacts
CourseOffering
Schedule
Professor
Course
Student
StudentArtifacts
![Page 38: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/38.jpg)
38
Review
What is an object? What are the four principles of object orientation? Describe each.What is a class? How are classes and objects related?What is an attribute? An operation?Define polymorphism. Provide an example of polymorphism.What is generalization?Why use packages?
![Page 39: Essentials of Visual Modeling with UML Module 3: Concepts of …read.pudn.com/downloads91/ebook/348025/DEV275_03... · 2004-03-16 · Essentials of Visual Modeling with UML Module](https://reader034.fdocuments.net/reader034/viewer/2022042221/5ec7df32bc89af77a976447a/html5/thumbnails/39.jpg)
39
Exercise: Principles of Object Orientation
The “OO Quiz Show” RulesEveryone in the class is assigned a number.The instructor displays a question.The instructor calls out a number.If the student answers the question correctly, the class continues to the next question.If the student does not answer the question correctly, the class goes back to the beginning.The game is over when all questions have been answered correctly.