Object-Oriented Programming Simplified

We know that object-oriented programming (OOP) is a programming paradigm that uses ‘objects’ to design software.

The aim of this is to bring it closer to you more clearly and simply.

Let us take a simple process in a higher education institution.

There is a higher education institute called ADC. It has students, teachers, staff and an administrator. A student has an opportunity to add or remove one or more courses that suit them. The teacher teaches the students and gives grades. The staff perform their tasks, and the administrator performs tasks such as overseeing operations and handling administrative tasks.

Object

Now we need to highlight all the entities that can be identified through this event.

Entities:  Institute (ADC), Student, Teacher, Staff, Administrator, Course

In Object Oriented Programming (OOP), what we do is break the programming task into objects. Here the objects are the same entities we mentioned earlier.

Methods

These entities have their own unique behaviors.

For example:

  • A student adds a new course or removes a course.
  • A teacher giving grades to students

In object-oriented programming, these behaviors are called ‘Methods’.

Attributes

Think about how to identify a student in higher education.

Suppose there are 25 students in a higher education institution. Someone inquiries about you from the institution of higher education. How to distinguish yourself from the 25 students at the institute?

That person may be using your name, student id or enrolled courses data.

Similarly, he asks about another student. Then he uses another student’s name, student id or enrolled Courses data.

In this way, he has used several properties(data) of the student to distinguish a student from the group of students. In this scenario, a student is an object. Thus, objects have certain properties. In OO programming they are called ‘Attributes’.

At any given time, the state of the object is determined by the values ​​of these properties.

In case of Student object, it has properties ‘Name’, ‘Student_Id, ‘Courses_Enrolled’ and ‘Grades’. The values ​​of ‘Name’ and ‘Student_Id’ can remain the same. But the values ​​of ‘Courses_Enrolled’ and ‘Grades’ may vary.

In relation to a student object, adding a new course (Add_Course ()) or removing course (Remove_Course ()) can be taken as methods of the object. The behavior of the object can change the value of the properties of that object. (By changing the values ​​of the properties of an object, the state of the object changes).

In our scenario, the state of the student is defined by its attributes.

If a student registers for a new course, the value of the Courses_Enrolled attribute changes. It shows the current state of the student object, different from the previous state.

Class

Higher education institution has multiple students, teachers, staff and courses.

A student’s name is ‘Saman’, and his student id is ‘1001218’. He has enrolled for ‘Pearson HND IT’ Course. The student id of another student whose name is ‘Kamal’ is ‘1002030’. He is enrolled in ‘Pearson HND Business’ Course.

Looking at these two Student objects, it appears that both have the same set of attributes (Name, Student_Id, Courses_Enrolled). Only the actual values ​​of those properties have changed.

Thus, a blueprint called a ‘Class’ is used to create objects of the same type. A class specifies the properties, methods, that its objects can have.

Now I think you have got a good understanding about the concept of object-oriented programming.

How can we identify Classes, Objects, Attributes and Methods from a given scenario?

First, the relevant scenario should be well understood. All the nouns that can be identified through the scenario should be highlighted. Thus, the Entities, attributes and actions in the scenario should be identified separately.

An entity represents an object. All the entities to be managed in the relevant scenario should be taken as objects.

Objects: Institute, Student, Teacher, Staff, Administrator, Course

Now objects with common characteristics and behaviors should be grouped into a single class.

In our higher education institution example, we can see many teachers, students, staff and courses. Teacher, student, staff and course are objects. Therefore, many different student objects, teacher objects, staff objects and course objects can be seen. Each of those objects has the same set of common characteristics. So, objects that show the same characteristics are classified.

That is, teacher, student, staff Course are the classes here.

Teacher, student, staff and administrator are person objects. Name, attribute is common to every person. Then if a class is created as Person, Student, teacher, staff and administrator also become person-dependent classes.

Name, address, teachers, students, staff, courses are common to all institutes, so the institute can be considered as a class.

Also, the institute can be considered as a class as it acts as a complex entity that manages and organizes various components like students, teachers, course administration processes etc.

Now let’s look at the verbs mentioned in the scenario. Verbs usually represent methods. It should be decided which class the method belongs to.

Now the attributes should be found. Attributes often represent the state or characteristics of a noun.

Now to identify the relationships between the classes, attention should be directed to the relationships mentioned in the scenario. It may include association, inheritance or dependencies.

How the classes are related to each other in our example:

  • Person is a general class, with Student, Teacher, Staff, and Administrator as subclasses.
  • Student is related to Course through enrollment.
  • Teacher is related to Course through teaching.
  • Administrator oversees the entire Institute and interacts with Staff.