Download - Class Relationships
![Page 1: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/1.jpg)
Class Relationships
Lecture Oo07Generalization Relationships
![Page 2: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/2.jpg)
References
Ambler, S., The Object Primer, Cambridge Univ. Press, 2001, Section 5.6
Fowler & Scott, UML Distilled Applying the Standard Object Modeling Language, AWL, 1997, Chapt 4,
![Page 3: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/3.jpg)
Teaching Points
Generalization Relationships Multiple Inheritance Base-class resolution
![Page 4: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/4.jpg)
Review
What good are different architectural views?
What view do Object Interaction Diagrams give?
![Page 5: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/5.jpg)
Class Diagrams
Provide a static view of the design The types of objects in the design and
the static relationship between them Three perspectives
– Conceptual– Specification– Implementation
![Page 6: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/6.jpg)
Conceptual Perspective
Concepts in the domain under study Related to classes in the final solution
but not directly Here we are really describing the
problem domain
![Page 7: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/7.jpg)
Specification
A view of the software design but an abstract perspective
Looking at interfaces Therefore we are describing types Type and Interface go together
![Page 8: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/8.jpg)
Implementation
A view which can describe the secrets of a class
The data structures may be visible in this view
Classes are being described (state and interface)
![Page 9: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/9.jpg)
Generalization (Inheritance)
The “kind-of” relationship Used to exploit the commonality of
objects The primary vehicle for “reuse” in OO Super-class/Sub-class Base-class/Derived-class
![Page 10: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/10.jpg)
GeneralizationUser
loginNamePassword
ClerknormalData
AdministratorspecialData
![Page 11: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/11.jpg)
What is a sub-class?
A subclass IS everything its base class is A subclass can extend the base-class
with new secrets/state A subclass can extend the base-class
with new interface/behavior A subclass can mask/change a specific
behavior of the base-class
![Page 12: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/12.jpg)
Various Perspectives
Conceptual– One thing is a special kind of another thing– Everything we can say about the general
thing is true of the specialized thing
![Page 13: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/13.jpg)
Various Perspectives
Specification– sub-typing (interface-inheritance)– interface of the more specialized thing
must contain all of the elements of the interface of the more general thing
– sub-type conforms to the super-type’s interface
![Page 14: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/14.jpg)
Various Perspectives
Implementation– sub-classing (implementation-inheritance)– generalization becomes inheritance as it is
associated with programming languages– sub-class inherits all the methods and
fields of the super-class
![Page 15: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/15.jpg)
Multiple Inheritance
User
AdministratorClerk
Manager
![Page 16: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/16.jpg)
Abstract Classes
Are objects normally instantiated from every class in a system?
UserloginNamePassword
AdministratorspecialData
ClerknormalData
Manager
![Page 17: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/17.jpg)
Mixin Classes
BulidingComponent
WallFloorRoof
Structural
Ornamental
Wood
ReenforcedConcreate
SteelPartition
![Page 18: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/18.jpg)
Ambiguity
What happens to common state/methods of the shared base-class?
It is not obvious whether base-class state/methods should be shared or be replicated
Example
![Page 19: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/19.jpg)
PersonnelRecordnameSIN
Addressstreetcity
TelephoneListingphoneNumber
EmployeeRecord
![Page 20: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/20.jpg)
UserloginNamePassword
AdministratorspecialData
ClerknormalData
Manager
![Page 21: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/21.jpg)
Resolving Ambiguity
C++ mechanisms– Scope resolution operator– Virtual Inheritance
![Page 22: Class Relationships](https://reader034.vdocuments.site/reader034/viewer/2022051419/56815ddf550346895dcc0718/html5/thumbnails/22.jpg)
Teaching Points
Generalization Relationships Multiple Inheritance Base-class resolution