Part of the keyboard clique

what is a object?

December 3, 2005 · 4 Comments

I thought I’d put down some ideas here now and in the future about this. I’ve been meaning to put this down somewhere for a long time, so why not here.This is for people looking to understand object orientation in a light different from the traditional approach. Did you learn that object orientation is about encapsulation, data hiding, inheritance and polymorphism? Don’t believe a word they say. It isn’t true. At least not in the way they put it.

I’d like you to take a different approach to object orientated programming. Put away all your ideas of encapsulation and polymorphism. They will only hinder you now.

Think systems. Systems consist of entities having responsibilities, that interact with eachother for some purpose.

Now, think people.

In your department, each of member knows who your manager is. His name, where his desk is, what time he comes to the office, where he lives. I’m new to you company. I need talk to the manager of your team, but I don’t know him. I know you. I ask you who the manager is. You point him out to me. I talk to your manager. What just happened?

It is the responsibility of each member of the team to know who the manager is. So when I need to speak with your manager, I came to ask you.

Object orientation is an approach that models responsibilities and interaction of the components of a system.

Let us translate the above scenario into an object oriented model:

1. You, I and the manager are entities in the system. Correspondingly, you, I and the manager are represented by objects in the software model of the system. Each of your team members are also represented by their respective objects in the software model.

2. The team must consist of members. Correspondingly, the team object will be a container of some kind. It could be a list data structure, that has a set of reference variables pointing to each member of the team.

3. Each member is responsible for telling anyone who asks who his/her manager is. Correspondingly, each object representing members of the team has a reference variable that points to their manager’s object, and a “getter� method that returns this reference to the caller.

4. You are the only member of the team that I know. So correspondingly, my object has a reference variable pointing to your object.

Now I need to speak with the manager. How do I find out who the manager is? I must ask you to show me who your manager is.

In object oriented terms, my object calls a method of your object. The job of this method is to return the reference to your manager that you have. Then my object calls methods of the manager object as appropriate.

Let me now list the basic features of object orientation:

  1. Object orientation is an approach to making a software model of a system.
  2. All entities in the system are represented by objects.
  3. Every object has responsibilities. These could range from providing information, to performing specific tasks.
  4. Entities in the model should get their work done by asking the right object to perform one of it’s responsibilities. So object orientation models the interactions between objects.

This is a simplistic description, but approaching a problem in this way is the first step.

The system to be modeled may be a real world scenario such as the one I mentioned, or something as mechanical as parsing logs and processing the information in them. Both can be modeled using the object oriented approach.

Object orientation is not the ideal approach in all situations. I’ll say more on this later sometime. I think that you should keep yourself open to using different approaches for systems of different scales. The best way to do this is not to think in terms of objects and methods. Think in terms of entities, their responsibilities, and interactions between entities in a system. With a bit of practice, it’s easy to translate this into the object oriented idiom. More on other approaches to design later.

Categories: Programming · object oriented programming

4 responses so far ↓

  • Jigar Gosar // December 2, 2005 at 9:26 am | Reply

    i strongly object to:
    “Did you learned that object orientation is about encapsulation, data hiding, inheritance and polymorphism? Don’t believe a word they say. It isn’t true. At least not in the way they put it.�

    these are Fundamental concepts of oop, if a layman cannot understand these principles than it dosent make it false.

    i appriciate the simplicity with whcih you are trying to approach oop, but making statements like “Don’t believe a word they say. It isn’t true� is lame. You need to make sure that, once ppl are more comfortable with oop paradigm, they need to understansd principles like Abstraction, Encapsulation, Polymorphism, Inheritance.

    I agree throwing all these jargons at a newcommer is not very polite (i couldnt think of a better word), but eventually he’ll have to master these concepts, if he’s to truely program the oop way.

    i (and everybody in this world, well almost) agrees to “Object orientation is not the ideal approach in all situations� we need to have all kind of tools in our arsenel, including procedural programming fundamentals. looking forward to read more…

  • ARGV // December 2, 2005 at 1:50 pm | Reply

    Hi Jigar,

    Thankyou for providing constructive criticism. I didn’t see it the way you did before, so when I read your comments it gave me pause for thought. I reflected on my motives for expressing my approach to encapsulation and polymorphism so strongly. I still think that this is the best way to start off. It’s to avoid the ambiguity that I added the line “At least not in the way they put it.�

    Many of those who read my post will not be clear about object oriented concepts. If they have heard about the concepts of encapsulation and polymorphism, they will almost certainly not be familiar enough with how to think with these concepts. Most academic institutions teach the concepts in an isolated fashion, without explaining how to think about object orientation.

    What I am trying to provide here is not just concepts. It’s about a way of thinking, which is even more basic.

    I’m going from my own experience of learning about object orientation. When I was taught these concepts I understood what the professors were saying clearly enough. I was however at a loss for how to apply these concepts to real programming tasks in a sensible way. So I used to mechanically or else randomly apply object oriented principles to my code, and that merely resulted in bad code. It wasn’t until I attended a presentation by Martin Fowler of thoughtworks.com, and read some chapters from his excellent book Refactoring, that I was able to reorient my thinking more sensibly.

    I’m not trying to undermine the venerable concepts of encapsulation and polymorphism. I think that these are names given to excellent patterns of thinking. I also think that explaining these patterns first will not properly encourage the reader to think about the reasons why those patterns are important. It is possible to teach such concepts to students first, and even have a student apply them correctly and well. But mostly the explanations and their corresponding applications will be very narrow.

    For example, people are taught that data hiding is good because the “getter� method can control how that data is accessed. This is true, and the concept can be applied effectively right here as is. But I think that data hiding can be more effectively explained using a different approach. My approach recognizes, teaches and inculcates the processes of thinking before naming them. I think that a thought-process-first approach encourages a better appreciation of why data hiding is needed. And then when the concept of data hiding is taught as a concept in itself, it will not be a foreign concept. The idea has already found it’s way into the students thought process at some point, and the teacher is now in a much better position to guide the student towards better code and design.

    A good many novice readers will approach object oriented programming with the preconceived ideas that they have learned in their academic institutions. These ideas may be correct. But due to the methods of teaching, they often come in the way of learning how to think.

    So my approach is to scrap all that you have learned. Let’s start from scratch. We’ll name the processes and concepts later. There will be many who will be unable to shake off what they have learned as I would like them, when following my approach. So I expressed myself in strong terms. I do not think this is lame. In any case, further posts will reveal that I have as much respect as you for polymorphism and encapsulation.

    This is not the first post, I’ll come to encapsulation and polymorphism a bit later. We’ll first learn how to start grappling with the the concept of a modeling system. Object oriented concepts will flow naturally from this.

    Some of you will disagree with my approach. Many of you might have different approaches to object orientation, or may believe that my approach is wrong. I hope you will all share your ideas with me. But I also hope that you understand why I approach these concepts they way I do.

  • Ruturaj K. Vartak // December 21, 2005 at 5:05 pm | Reply

    An interesting article,
    would be waiting for more

  • Mohit // March 23, 2006 at 2:58 pm | Reply

    What is not an Object?

Leave a Comment