Thinking in Objects


Object Oriented Programming (OOP) is something that is commonplace. PHP, since version 5 have fully embraced OOP. Even today, I am not sure I have enough knowledge of OOP. But, here is what I understand about thinking in objects:

Functional programming is about functions. Most of the time function libraries are mapped to a table on the database. At least that is what I have been doing for the past 13 years.

Object Oriented Progra

mming on the other hand challenges us to think in, well, “objects”.

For example, Employee.

The way I used to write the function library is “insert_employee”, “edit_employee”, “delete_employee”, “get_employee_list”, “get_employee_by_id”, etc…

But, in ob

jects. an Employee is defined as what it is and what it can do. So, thinking in object, we “create” an instance of employee. It will have name, age, gender as properties. Things that usually written as fields in the database.

Then we define the employee action:

1. DoOvertime

2. RequestLeaveOfAbsence

These action are translated into methods.

Coming from a As you can see, the approach is very different. Instead of focusing on the database and writing functions around them, we are creating an entity, or an “object” and the database is actually built around the object.

Now, for a great read on OOP and thinking in objects, I suggest you read Allen Holub article on Javaworld “Building user interfaces for object-oriented systems“. I know it is old stuff, written in 1999, but the concept is great and still relevant today.