22
Class Relationships Lecture Oo07 Generalization Relationships

Class Relationships

  • Upload
    ilori

  • View
    21

  • Download
    0

Embed Size (px)

DESCRIPTION

Class Relationships. Lecture Oo07 Generalization Relationships. 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, . Teaching Points. - PowerPoint PPT Presentation

Citation preview

Page 1: Class Relationships

Class Relationships

Lecture Oo07Generalization Relationships

Page 2: Class Relationships

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

Teaching Points

Generalization Relationships Multiple Inheritance Base-class resolution

Page 4: Class Relationships

Review

What good are different architectural views?

What view do Object Interaction Diagrams give?

Page 5: Class Relationships

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

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

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

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

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

GeneralizationUser

loginNamePassword

ClerknormalData

AdministratorspecialData

Page 11: Class Relationships

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

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

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

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

Multiple Inheritance

User

AdministratorClerk

Manager

Page 16: Class Relationships

Abstract Classes

Are objects normally instantiated from every class in a system?

UserloginNamePassword

AdministratorspecialData

ClerknormalData

Manager

Page 17: Class Relationships

Mixin Classes

BulidingComponent

WallFloorRoof

Structural

Ornamental

Wood

ReenforcedConcreate

SteelPartition

Page 18: Class Relationships

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

PersonnelRecordnameSIN

Addressstreetcity

TelephoneListingphoneNumber

EmployeeRecord

Page 20: Class Relationships

UserloginNamePassword

AdministratorspecialData

ClerknormalData

Manager

Page 21: Class Relationships

Resolving Ambiguity

C++ mechanisms– Scope resolution operator– Virtual Inheritance

Page 22: Class Relationships

Teaching Points

Generalization Relationships Multiple Inheritance Base-class resolution