|
Data Structures and Algorithms
with Object-Oriented Design Patterns in Python |
A Python class defines a data structure that contains instance attributes, instance methods, and nested classes. In Python the class of an object and the type of an object are synonymous. Every Python object has is a class (type) that is directly or indirectly derived from the Python built-in object class. The class (type) of an object determines what it is and how it can be manipulated. A class encapsulates data, operations, and semantics. This encapsulation is like a contract between the implementer of the class and the user of that class.
The class statement is what makes Python an object-oriented language. A Python class definition groups a set of values with a set of operations. Classes facilitate modularity and information hiding. The user of a class manipulates object instances of that class only through the methods provided by that class.
It is often the case that different classes possess common features. Different classes may share common values and they may perform the same operations. In Python such relationships are expressed using derivation and inheritance.