OOP
OOP
Encapsulation in Python
Inheritance in Python
Python Class
A class is a collection of objects. A class contains the blueprints or the prototype
from which the objects are being created. It is a logical entity that contains some
attributes and methods.
To understand the need for creating a class let’s consider an example, let’s say you
wanted to track the number of dogs that may have different attributes like breed,
and age. If a list is used, the first element could be the dog’s breed while the second
element could represent its age. Let’s suppose there are 100 different dogs, then
how would you know which element is supposed to be which? What if you wanted to
add other properties to these dogs? This lacks organization and it’s the exact need
for classes.
Types of Inheritance
We can organize classes into a hierarchy when they have some common features.
This will allow us to derive new classes from existing classes.
A class, from which another class is derived, is called a super class or parent class.
A new class, which is derived from an existing class, is called a sub class or child
class. A sub class inherits all the data and operations/methods of the super class. In
addition, a sub class can have its own data and operations/methods.
Sub classes have an “is-a-kind-of” relationship with the super class. e.g. part time
employee is a kind of an employee.
Python Encapsulation
In Python object oriented programming, Encapsulation is one of the
fundamental concepts in object-oriented programming (OOP). It describes the
idea of wrapping data and the methods that work on data within one unit.
This puts restrictions on accessing variables and methods directly and can
prevent the accidental modification of data. To prevent accidental change, an
object’s variable can only be changed by an object’s method. Those types of
variables are known as private variables.
A class is an example of encapsulation as it encapsulates all the data that is
member functions, variables, etc.
Message Passing in python
Message passing in Python refers to the method of communication between
different parts of a program, especially in concurrent or distributed systems.
There are several ways to implement message passing in Python: