Revisiting Object-Oriented Programming (OOP)

Johnson Liu
4 min readJun 28, 2021

As a programmer or even as someone who is starting off learning how to write code, the concept of OOP is a very big concept you will have to learn. Often times, as a new programmer or engineering student, you hear the term OOP (O O P, not oops) but don’t know what it is. OOP stands for Object-Oriented Programming.

Object-oriented programming (OOP) is a computer programming model that organizes software design around data, or objects, rather than functions and logic. It allows developers to focus what to manipulate in comparison on how to manipulate a program. This approach is suited for large, complex, and actively maintained applications. In OOP, an object can be defined as a data field that has unique attributes and behavior.

According to Sarah Lewis from Tech Target, Object-oriented programming is based on the following pillars or principles:

  • Encapsulation. The implementation and state of each object are privately held inside a defined boundary, or class. Other objects do not have access to this class or the authority to make changes but are only able to call a list of public functions, or methods. This characteristic of data hiding provides greater program security and avoids unintended data corruption.
  • Abstraction. Objects only reveal internal mechanisms that are relevant for the use of other objects, hiding any unnecessary implementation code. This concept helps developers more easily make changes and additions over time.
  • Inheritance. Relationships and subclasses between objects can be assigned, allowing developers to reuse a common logic while still maintaining a unique hierarchy. This property of OOP forces a more thorough data analysis, reduces development time and ensures a higher level of accuracy.
  • Polymorphism. Objects can take on more than one form depending on the context. The program will determine which meaning or usage is necessary for each execution of that object, cutting down the need to duplicate code.

When learning OOP, inheritance and relationship is one of the most common concepts that is used throughout (especially in ruby). The three most common relationships you will run into are:

  • The Belongs to Relationship
  • The Has Many Relationship
  • The Has Many Through/Many to Many Relationship
Belongs to Relationship

The belongs to relationship is straight forward. When you are building an application, you usually have a user class. There will always be an object that belongs to the user. Many things can belong to a user such as a book, a car, a key, a home. And the example above, a phone belongs to a user.

Has Many Relationship

The has many relationship tree is usually going in one direction. Once again we will use the user class and say a user can potentially have many items such as shoes, devices, meals, etc. In our example above, a user has many reviews.

Many to Many/Has Many Through Relationship

The most complicated relationship, but also most useful one is always the many to many/has many through relation. In our example above, our two main classes are our user class and our product class. We could potentially have a user has many products/a product has many users table, but it would be too simple. When we implement a joiner class such a favorites or reviews, it makes our application much more dynamic, and allows us to have many more user stories. In an example. a user has many products through reviews not only links a user to having many products, but also allows the user to leave a review on that product.

This is just a simple run through on OOP relationship, and I encourage you to research more and practice on. The following languages are also OOP oriented:

  • Java.
  • JavaScript.
  • Python.
  • C++
  • Visual Basic . NET.
  • Ruby.
  • Scala.
  • PHP.

--

--