Agile FAQs
  About   Slides   Home  

 
Managed Chaos
Naresh Jain's Random Thoughts on Software Development and Adventure Sports
     
`
 
RSS Feed

Recent Thoughts
Tags
Recent Comments

There is No Spoon (Objects)

In OO, frequently, we get caught up in modeling our objects based on our perspective of the real world. Since everyone’s perspective is different we end up with a lot of thrashing and confusion. We end up arguing about these models in the air, baselessly. For example in a Veterinarian Information System (system responsible for billing and patient history), we end up arguing whether the Patient class should have a getShot(Vaccination) or should the Doctor class have a giveShot(Vaccination) method. In the end (when we finally start implementing the system) we realize that it really does not matter who gives the shot or takes the shot. What really matters is that we have recorded what shot was given to which patient. So we end up creating a Visit class with a method called add(Procedure).

Long story short, there are no real-world objects, its all how we perceive things. If we try to model our software based on our understanding of the real world, the software would also be as complex as our understanding of the real world. Since in software we are dealing with creating abstractions, we really want to focus on behavior rather than Objects. TDD is a great way to do this.

We start off with a test which expects that our system will exhibit some Behavior. At this point, we don’t know or care about which Object/s will provide this behavior. To make the tests work, we start creating methods that we need from our objects on the test for the time being. Once we have our test working, then we ask yourself, where does this behavior really belong? Sometimes real world objects pop-up. Sometimes we create Objects that don’t exist in real world. This is important because it helps us make our design simpler and more expressive. Slowly we expect more behavior from our system (by writing new tests) which starts flushing out our objects.

  • Kalpesh

    We are taught to think in terms of nouns/verbs and real-world thing.
    And there is no one way in which real world example work, as you said above (is it patient receiving shots or doctor giving shots?)

    I think OO, when used with real example will turn out to be a different thing compared to what we are taught.

    IMO, it neither belongs to patient nor doctor. It depends on the context, usage & the best fit case (add the method where it serves the purpose well).

  • Kalpesh

    We are taught to think in terms of nouns/verbs and real-world thing.
    And there is no one way in which real world example work, as you said above (is it patient receiving shots or doctor giving shots?)

    I think OO, when used with real example will turn out to be a different thing compared to what we are taught.

    IMO, it neither belongs to patient nor doctor. It depends on the context, usage & the best fit case (add the method where it serves the purpose well).


    Licensed under
Creative Commons License