Legislative Chair LeRoy E. Young, DO, OOA ... - MemberClicks
Object-Oriented Programming Introduction to UML Class...
Transcript of Object-Oriented Programming Introduction to UML Class...
![Page 1: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/1.jpg)
ObjectObject--Oriented Programming Oriented Programming Introduction toIntroduction to
UML Class DiagramsUML Class Diagrams
CSIE Department, NTUT
Woei-Kae Chen
![Page 2: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/2.jpg)
UML: UML: Unified Modeling LanguageUnified Modeling LanguageSuccessor to OOA&D methods– late 1980s and early 1990s
Unifies– Jacobson & OMT (Booch & Rumbaugh)
Graphical notation used to express designs– Use cases– Class diagrams– Interaction diagrams
Sequence diagramsCollaboration diagrams
– Package diagrams– State diagrams– Activity diagrams– Deployment diagrams
GoF Book
![Page 3: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/3.jpg)
UML class diagramsUML class diagramsThree perspectives– Conceptual
represents of the domain under studyrelate to the class that implement them, but often no direct mapping
– Specificationlooking at types rather than classesa type represents an interface that may have different implementations
– Implementationlooking at classes for our OOP class
![Page 4: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/4.jpg)
UML: a classUML: a class
function1()function2()
variable1variable2
class_name+ public# protected- private
AbstractConcrete
•data type•parameter
![Page 5: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/5.jpg)
Example: OBSort1Example: OBSort1.cpp.cpp
+getInput()+printOutput()+Sort()+cleanUp()+getSize()
-a-size
IntArray
![Page 6: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/6.jpg)
Example: OBSort1Example: OBSort1.cpp.cpp
+getInput()+printOutput()+Sort()+cleanUp()+getSize()
-a-size
IntArray
Context(main)
Let’s assume main() is a class
relationship
![Page 7: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/7.jpg)
UML: class relationshipUML: class relationshipAssociation (knows a)Dependency (uses a)Composition (has a)Aggregation (has a)
Inheritance (is a)
Class template XY
X Y
X Y
X Y
X Y
Y
X
(parameterizedclass)
![Page 8: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/8.jpg)
““Uses aUses a”” ““Knows aKnows a”” relationshiprelationship
“Uses a”– Dependency– One object issues a function
call to a member function of another object
“Knows a”– Association– One object is aware of
another; it contains a pointer or reference to another object
X Y
X Y
![Page 9: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/9.jpg)
““Is aIs a”” ““Has aHas a”” relationshiprelationship“Is a” relationships– Inheritance– a class is derived from
another class
“Has a” relationships– Composition or Aggregation– a class contains other
classes as members
X
Y
X Y
X Y
![Page 10: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/10.jpg)
Aggregation Aggregation CompositionComposition
Both are “Has a” or “part-of” relationshipComposition– a stronger variety of aggregation– the part object may belong to only one whole– expected to live and die with the whole
delete whole delete partAggregation– cascading delete is often– an aggregated instance can be shared
X Y X Y
![Page 11: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/11.jpg)
Example: Example: ““has ahas a”” relationshiprelationship
colorisFilled
Style
Polygon
13..*
Point
*
1
{ordered}
radiusCircle
1
1
*1
Multiplicity
a Point may appear in only one Polygon or Circle
a Style may be shared by many Polygons and Circles
Delete Polygon delete PointDelete Polygon delete StyleX
![Page 12: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/12.jpg)
UML Example (C++): AssociationUML Example (C++): AssociationX Y
class X {X(Y &y) : y_ref(y) {}void SetY(Y *y) {y_ptr = y;}void f() {y_ptr->doIt();}
...Y *y_ptr; // pointerY &y_ref; // reference
};
![Page 13: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/13.jpg)
UML Example (C++): DependencyUML Example (C++): Dependency
X Y
class X {
...
void f1(Y y) {...; y.doIt();}
void f2(Y *y_ptr);
void f3(Y &y_ref);
};
![Page 14: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/14.jpg)
Example: OBSort3Example: OBSort3.cpp.cpp
+getInput()+printOutput()+cleanUp()+getSize()+operator[]()
-a-size
IntArray
+sort()
Sorter
uses•getSize()•operator[]
![Page 15: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/15.jpg)
UML Example (C++)UML Example (C++): Composition 1: Composition 1
X Y
class X {
...
Y a; // 1; Composition
Y b[10]; // 0..10; Composition
vector<Y> c; // ??
};
Java?
Composition of vector<Y>
NOT Composition of Y
![Page 16: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/16.jpg)
UML Example (C++):UML Example (C++): Composition 2Composition 2
X Y
class X {X() { a = new Y[10]; }~X(){ delete [] a; }
...Y *a; // 0..10; Composition
};NOT Association
![Page 17: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/17.jpg)
UML Example: OBSort3UML Example: OBSort3.cpp.cpp
+getInput()+printOutput()+cleanUp()+getSize()+operator[]()
-a-size
IntArray
+sort()
SorterContext(main)
![Page 18: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/18.jpg)
UML Example (C++):UML Example (C++): Aggregation 1Aggregation 1
X Y
class X {X() { a = new Y[10]; }~X(){ delete [] a; }
...Y *a; // 0..n; Aggregationvector<Y> b;// Y’s are instantiated
// and destroyed by X};
The same as composition?
May be considered as aggregation of Y
![Page 19: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/19.jpg)
UML Example (C++):UML Example (C++): Aggregation 2Aggregation 2
X vector<Y> Y
class X {...vector<Y> b;
};
X Y
Hiding implementation detail
Implementation detail
![Page 20: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/20.jpg)
UML Example (C++): InheritanceUML Example (C++): Inheritance
class Y {...};
class X : public Y {...};
X
Y
“is a” relationship
![Page 21: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/21.jpg)
Example: OOSort2Example: OOSort2.cpp.cpp
+getInput()+printOutput()+cleanUp()+getSize()+operator[]()
-a-size
IntArray
+sort()
SorterContext(main)
+sort()
-compareCount-exchangeCount
CountingSorter
![Page 22: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/22.jpg)
UML Example (C++):UML Example (C++):Template ClassTemplate Class
template <class T>class X {.........};
XY
...X<Y> a;...
![Page 23: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/23.jpg)
![Page 24: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/24.jpg)
![Page 25: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/25.jpg)
Abstract class
![Page 26: Object-Oriented Programming Introduction to UML Class Diagramswkchen/courses/goop921/lectures/lectur… · zSuccessor to OOA&D methods – late 1980s and early 1990s. zUnifies –](https://reader035.fdocuments.in/reader035/viewer/2022071103/5fdcdebf240ef942946d0117/html5/thumbnails/26.jpg)
C++ static member