Title: Chapter 2 Lesson 4: Modeling Relationship Among Classes
1Chapter 2 Lesson 4 Modeling Relationship Among
Classes
2Last Time
- Classes
- Objects
- Message Passing
- Modularity
- Abstraction
- Encapsulation
- Polymorphism
3Modeling Relationship and Structures
- Class diagrams used to model static Structures of
Object-Oriented Software Systems and relationship
among classes - Class diagrams consists of
- A set of nodes that represent classes and
interfaces - A set of links that represent relationships among
classes
4Relationship that can Modeled using Class Diagrams
- Inheritance, including extension and
implementation - Association, including aggregation and
composition - Dependency
5Inheritance
- Inheritance defines a relationship among classes
and interfaces. - There a several forms of inheritance
relationship - Extension relation between two classes. When
class C2 extends class C1, class C2 is known as a
subclass of class C1, and class C1 is known as a
superclass of class C2 - The extension relationship between two
interfaces. When interface I2 extends interface
I1, interface I2 is known as a subinterface of
interface I1, interface I1 is known as a
superinterface of interface I2
6Inheritance
- The implementation relationship between a class
and an interface. When class C2 implements
interface I1, class C2 is known as an
implementation of interface I1
7Inheritance
Interface
- The implementation relationship between a class
and an interface. When class C2 implements
interface I1, class C2 is known as an
implementation of interface I1 - Other examples blender, car, bike, etc.
Code Java, Classes gets implemented
8UML Terminology for Inheritance
- Specialization ? Extension
- Generalization ? the inverse of specialization
- Realization ? Implementation
9Graphical Representation of Inheritance
Superclass
Superinterface
Interface
Subclass
Subinterface
Implementation
Extension Of interfaces
Implementation of Interfaces
Extension of classes
10Graphical Representation of Inheritance
- Extension relationship solid line
- Implementation relationship dashed line
- In class diagrams
- Regular class, fields methods Regular Roman
fonts Example TriangleClass - Interface and methods in italic fonts
11Conceptual Model of Inheritance
- Inheritance Models the is-a(n) relationship in
the real world, i.e., if C2 is a
subclass/subinterface/implementation of C1, then
every instance of C1 is an instance of C2, and
everything that applies to instances of C1 also
applies to instances of C2 - Extension relationship between classes commonly
associated with notion of reusing or sharing the
implementation (i.e., fields and methods) of the
superclass by its subclass
12Class Diagram Inheritance Relation Among Classes
Representing U.S Government
U.S. Government
Congress
Executive
Judicial
Senate
House
13Inheritance Levels of Abstraction
- Superclass represents more general abstractions
- Subclasses Represents more specialized
abstraction