What is Object Oriented Programming (OOP)

In this blog, I wanted to first fully understand what OOP really means, so I started researching the web and old textbooks. I am very glad I did as it really made things a lot clearer for me as well as increased my desire to learn ruby language. Below is my summary on the subject.

Object-oriented programming (OOP) is a programming paradigm that represents concepts as “objects” that have data fields (attributes that describe the object) and associated procedures known as methods. Objects, which are usually instances of classes, are used to interact with one another to design applications and computer programs.

https://en.wikipedia.org/wiki/Object-oriented_programming

Understanding Objects

The word “Object” could refer to a table, car, guitar and so on, we are comfortable with these as objects we interact with in real life. These are still valid objects in software engineering, but there are other types of objects which at first might seem strange to a beginner/none-programmer, these are those objects that are more of a realistic way of grouping similar features, so say am I am building a login system, I might have methods such as, login, logout, forgot password, register, remember me, now all these methods can be grouped into a single object called “Authorisation”, although it is not what we would call an object in real life, it makes programmatic sense to use it as an object.

I will use an example of a salon booking system requirement to explain how you can identify objects both obvious objects and other types of objects.

You have been approached to create a booking system for a salon, customers will be able to call and book a stylist for specific date and time, customer will be matched to a stylist depending on the chosen style.

Identifing the objects

First I identify the actors in the system as those will be the obvious objects, the rest of the objects come in the form of those things our actors do that we wish to record against each other, below is how I generated the objects for the salon:

  • The immediate actors that form objects are customers and stylists. So we can safely add those to our object list.
  • Customer books an appointment so I might want to record all the appointments for any given customer, this gave me customer appointments object.
    I also want to make a record off all possible styles so this can be another object.
  • Stylists specialise in doing different styles, so it makes sense to have an object that records styles against stylists, this can be called stylist styles object.

So using this method we can see the possible objects as follows:

  1. Customers
  2. Stylists
  3. CustomerAppointments
  4. Styles
  5. StylistStyles

What can I find in an object?

An object would typically have methods and attributes.

Attributes help distinguish a difference between objects of the same kind, so two customer objects would have different customer id attributes. Example of customer attributes are:

  • Customer Id
  • Name
  • Address
  • Telephone
  • Date of Birth

The methods are the things you can do with the customer attributes. e.g:

  • Add New Customer
  • Update Existing Customer
  • Get All Customers
  • Delete Customer Record

This is my understanding of objects with a sense of simplicity as not to confuse me now or when I read this article back to myself in the future, but please feel free to add to it in your comments. In the next post I will look at objects from the perspective of the programming language of ruby as well as find out if some programming languages are better with objects than others.

Tags: ,