Learn Before
Class Composition
Where inheritance represents an "Is-A" relationship, composition represents a "Has-A" relationship. For example, a Car is a type of Vehicle. To represent these as classes, Car would be a child class of Vehicle, inheriting some of its members (four tires, a steering wheel, etc.) and some of its methods (such as a method for Move() or Stop()). However, this isn't the only way to structure a relationship. You could represent a Car as a class that Has instances of other classes which provide it the functionality a Car would need. You could have two classes, called Move and Stop, which Car has an instance of in its constructor. Typically the class that Has the other classes is referred to as the Composite class, because it is composed of other classes (the Car is composed of Move and Stop). The classes that the Composite class contains are referred to as Components (the Move and Stop class are Components which make up the Car class).
0
1
Tags
Python Programming Language
Data Science
Related
Defining Classes in Python
Class Variable vs Instance Variable
Class Inheritance
"Self" Keyword in Python Class
init() method in Python
Methods vs. Functions
Encapsulation in Python
Class Composition
Math Constants
Math Constants
Useful Math Constants in Python
The add_to_class Utility Function
The HyperParameters Utility Class
The ProgressBoard Utility Class
Base Module Class in Deep Learning Implementation