A Quick Look into OOP
Have you ever wondered how modern complex software applications are built and organized? In this article, we’ll take a quick look at Object Oriented Programming (OOP), which is a fundamental style of programming in software development.
What is OOP?
In the past, programs were primarily procedural or structural, which means that the instructions were expressed step by step. While this approach is good for small programs, when the complexity of the application grows there was a need for something more convenient to handle these challenges. That is where the concept of OOP comes into play.
OOP is a style that is based on the concept of objects. These objects can contain properties and methods. In OOP, we represent real world objects within our code. Let’s take a car for an example: some of its attributes could include color, model, mileage, etc and these would be the properties. Some of the actions could include starting, stopping, and accelerating etc. and these would be the methods.
There are 4 pillars in OOP. They are abstraction, inheritance, polymorphism and encapsulation. Let’s dive deeper into these concepts in upcoming articles.
Why OOP matters?
It is vital to have an understanding of OOP, given that it is the base of modern software design. In OOP, we create classes which contain the properties and methods. For an example, we can create a class called ‘Book’, which contains all the attributes and the methods related to the Book object. Let’s look at some of the benefits of using OOP in our application.
Reusability
OOP facilitates code reuse. Consider a library system with various book types. Instead of creating separate classes for each book type, such as fiction, novels, and short novels, which would result in repetitive code, OOP allows us to create a generic class named ‘Book’ and create objects from that class. We can then define subclasses and inherit properties and methods from the parent class. This approach eliminates the need to duplicate code, promoting efficiency in software development.
Modularity
In OOP, modularity is another significant advantage. Returning to our library system example, we can achieve the code modularity by encapsulating the unique characteristics of each book within its subclass. This approach ensures that if we want to make a change to a specific book type, that does not disrupt the functionality of other book types or Book class.
Flexibility
Flexibility is another advantage of OOP. Imagine in our library system, where we have Ebook and PhysicalBook subclasses inherited from the Book parent class. However, the functionality for the returnBook() and borrowBook() differs between Ebook and PhysicalBook. In this scenario, we can simply override the methods from the parent class within the subclasses, allowing us to adapt and modify the code as we needed. Here, the concept of polymorphism is used.
Security
OOP enhances the security through the use of abstraction and encapsulation concepts by safeguarding the sensitive data and exposing only the necessary functionalities for the user. This makes the software more secured and robust specially when dealing with the sensitive and confidential information.
Basic OOP Terminology
So far, we have encountered several OOP terminologies, and now, let’s look into them to understand what those really mean.
Class is a blueprint for an object which contains set of properties and methods that are common to all the objects of that class. This defines the structure and the behavior of the objects belonging to it. In the context of library system example, we can consider Book as a class.
Object is an instance of a class created based on the class’s blueprint, representing the real-life entities. When the class is instantiated memory is allocated. We can create objects from the Book class regarding the previous example.
Methods are the functions that are defined inside the class which describes the behavior of an object. In the Book class, for instance, methods such as borrow() and return() can be defined.
Attributes are the properties of an object which define its state. For an example, a Book class can have attributes such as title, author, and year.
Now that we have reached to the end of this article and now we have a basic understanding of OOP. In the next articles let’s look into the basic OOP concepts one by one to get a solid understanding of each of them.
Thank you for reading my blog post. Happy Learning!!!
Sources : https://www.geeksforgeeks.org/introduction-of-object-oriented-programming/