220 likes | 318 Views
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.
E N D
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 • Generalization Relationships • Multiple Inheritance • Base-class resolution
Review • What good are different architectural views? • What view do Object Interaction Diagrams give?
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
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
Specification • A view of the software design but an abstract perspective • Looking at interfaces • Therefore we are describing types • Type and Interface go together
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)
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
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
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
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
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
Abstract Classes • Are objects normally instantiated from every class in a system?
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
Resolving Ambiguity C++ mechanisms Scope resolution operator Virtual Inheritance
Teaching Points • Generalization Relationships • Multiple Inheritance • Base-class resolution