OOP: Classes and Objects

Image result for python classes

Unfortunately, not all useful abstractions are built in. Programming languages that allow the programmer to define new classes of objects are called object-oriented languages. These languages also support a style of programming called object-oriented programming. Unlike object-based programming, which simply uses ready-made objects and classes within a framework of functions and algorithmic code, object-oriented programming sustains an effort to conceive and build entire software systems from cooperating classes.

The class definition syntax has two parts: a class header and a set of method definitions that follow the class header. The class header consists of the class name and the parent class name. The class name is a Python identifier. Although built-in type names are not capitalized, Python programmers typically capitalize their own class names to distinguish them from variable names.

The parent class name refers to another class. All Python classes, including the built-in ones, are organized in a tree-like class hierarchy. At the top, or root, of this tree is the most abstract class, named object, which is built in.

Each class immediately below another class in the hierarchy is referred to as a subclass, whereas the class immediately above it, if there is one, is called its parent class. If the parenthesized parent class name is omitted from the class definition, the new class is automatically made a subclass of object.

Before writing a line of code, think about the behavior and attributes of the objects of the new class. What actions does an object perform, and how, from the external perspective of a user, do these actions access or modify the objects state?

Leave a comment