As I recently discovered, Object-Oriented Programming (OOP) is a programming language that is based on objects (as the name suggests) instead of actions and logic. In the past, computer programs were more focused on solving problems and they were written in a manner that focused on this process, rather than the items involved in it. With OOP, the focus shifted to the objects used in solving the problems and made the language revolve around them.
The first OOP language was called Simula. Today, most of the popular languages used are OOP languages: Java, Python, C++, and others. For OOP, we first identify the objects that are relevant to us. Once we've done that, we can group similar objects together to create a class (ex: building). Within that class, we can have different types of that class called subclasses (ex: apartment building, office building, skyscraper) and the benefit of OOP is that it has inheritance: each subclass inherits the properties of the parent class. This way, we can even divide "office building" into subclasses and they will each inherit all of the properties of "office building" as well as the properties of the class "building". This saves time and redundancy in the code. Within each class we have methods that perform actions on the class and allow us to manipulate it.
The advantages of OOP are numerous, but a few main ones are:
- New users of an OOP language are able to create their own classes: they are not limited to the ones already available. This way endless possibilities arise for new objects, and they can be whatever the user needs.
- Classes can be reused, which saves time and lines of code. They can not only be reused in their own program, but also in other OOP languages, which is extremely useful for distribution between networks.
- Though not implemented in Python, OOP programs can control what is shown to the user. They can make something public or private, and so the user only sees what the programmer wants them to see, and only what they need to see.
And that's it for Object-Oriented Programming. Here is an image to help understand it.