Object Oriented Programming (OOP) in Python.
What is OOP ?
OOP (Object Oriented Programming) is an object-oriented programming method. The purpose of the OOP was created to facilitate program development by following the existing models in everyday life. So every part of a problem is an object, now the object itself is a combination of several smaller objects.
A large object is formed from several smaller objects, these objects communicate with each other, and send messages to other objects.
OOP concepts.
- Abstrack Class
Class is an abstract description of information and behavior from a set of data. Can be illustrated as a blueprint or prototype that is used to create objects. Class is a data type for objects that encapsulate data and operations on data in a single unit and a data type for objects that encapsulate data and operations on data in a single unit.
- Encapsulation
Encapsulation is actually a combination of data and functionality in a single unit as a form of hiding detailed information. Encapsulation makes it easier for us to use an object from a class because we don’t need to know everything in detail and emphasizes the interface of a class, or in other words, how to use certain class objects.
- Inheritance
We can define a new class by inheriting properties from other existing classes.
Derivation of this trait can be done in stages, so that the lower the class becomes more specific.
Sub classes allow us to perform detailed specification and special behavior of their super classes.
With the concept of inheritance, a programmer can use the code he has written in the super class over and over again in the derived classes without having to rewrite all the code.
- Polymorphism
Polymorphism is the ability of objects of different classes but related in inheritance to respond differently to the same message.
Polymorphism can also be said to be the ability of an object to decide which method to apply to it, depending on where the object is at the inheritance level.
Overriding method.
Method name overloading.