Object oriented programming is a useful way of organizing code and representing data. The basics of object oriented programming (OOP) are to create a class, which is an instance of an object. A programmed class has it's own variables and methods associated with it.
For example, a car is a class, made up of various parts and attributes such as the number and type of tires, horsepower, torque, gas mileage, etc. An example in code would look like this:
class Car(object):
def __int__(self, gascapacity):
self.numwheels = 4
self.wheeltype = "offroad"
self.gascapacity = gascapacity
def gasmileage(Car.gascapacity):
#calculations here
As you can see from the above, very basic example, classes and object oriented programming allow for instance variables as well as methods to be defined and contained within an organized class, thereby containing various calculations and functions within a single "object". The main benefit to programmers is that objects can be programmed and then used wherever needed. In my example, a Car object that defines a car and calculates gas mileage could be imported in a variety of projects, and isn't restricted to just one person.
Another benefit to OOP is the ease of expansion. It would be very easy to modify the above Car class to include other information and methods, such as a method for calculating when wheels need to be changed or to tell when oil levels are low.
All in all, object oriented programming allows for ease of organization, better and cleaner sharing of premade code for use in other projects, and allows for more functionality to be added as needed.
Akshay, can you think of problems that are not suitable for OOP paradigm? What are disadvantages of OOP?
ReplyDelete