top of page

Object Oriented Programming Part 1: Basic Principle

Object-Oriented Programming (OOP) is a programming concept where the software design is based on an Object that contains states and behavior. This information is stored in simple, reusable code blueprints called Class.


States of an object are represented by attributes or variables, whereas an object’s behavior is defined by functions or methods. Examples for OOP language include Python, Java, C++, C#, R, and many more.


For example, we want to define cars in our program and their three characteristics: their model, current speed, and price. Moreover, the car could increase or decrease its current speed depending on the command.


First, we create a Class with the name Car that contains the three variables: car_model, current_speed, and price. Second, we create two methods of changing the speed that is Step_the_gas and Step_the_brake.


Lastly, we could define cars by setting the values for the variables and this blueprint are reusable for any number of cars. You could observe the code of this example (in Python Language) in the picture below.



Each object could be manipulated without interrupting other objects. For example, we could change the price of Object myCar from 10000 to 12000 by simply assign it to a new value without affecting others.



Another way to manipulate the object is through functions or methods. The Step_the_gas and Step_the_brake functions alter the current speed variable by 10 (pre-determined).



OOP designs provide many benefits because of their Important principles for designing an efficient program namely Inheritance, Encapsulation, Abstraction, and Polymorphism. We discuss these four principles in the next part.

3 views0 comments

Comments


bottom of page