Four types of relationships
There are four possible relationships between classes.
- Association, in which one class calls a method in another class. This is represented by a plain line or a line with an arrow.
- Inheritance, in which a class extends another class and inherits all the public fields and methods. Generally a class inherits from a class of the same kind. The child class is a type of the parent class. Employee could inherit from the person class because an employee is a type of person. Inheritance is represented by a line with an empty triangle on one end. The triangle always points to the parent class.
- Aggregation, in which a class is contained in another class, but also has an independent existence in the program. For instance, in Product, magazines contains a list of magazine objects. Magazines have an existence separate from the product class and so the relationship is aggregation. An aggregation is considered a "has a relationship. Product has a list of magazines. It is represented with a line with a clear diamond on one end of the line. The diamond always points to the containing class.
- Composition, in which a class is contained in another object but has no independent existence. In the diagram below the subscription is shown as composition. The subscription has no existence separate from the customer.
First Diagram
This diagram has no inheritance. Most of the relationships are aggregation with one instance of composition. I did an association between notice and customer.

Diagram two
One of the big drawbacks of python as an object oriented language is that it doesn't have interfaces.An interface is a class like object that only contains abstract methods. Any class that implements an interface must give a body to all the methods of the interface. Interfaces are usually diagrammed like inheritance.
You might notice several classes have similar methods for dealing with lists, methods for adding, editing and removing objects from lists. In another language one could create an interface ot encapsulate these methods and each of the classes with lists could implement that interface.
In the diagram below I made an abstract class to act like an interface. An abstract class is a class with abstract methods. An abstract class can never be accessed directly, only through child classes that extend it. This is not ideal, because the classes inheriting from this abstract class are not of the same type. A customer is not a type of listmanagement. But it will work and it shows the look of inheritance.

No comments:
Post a Comment