The Pragmatic Craftsman :: Simplicity from complexity ::

Thoughts on Object Oriented Programming

Object Oriented programming is hard. It’s easy to program in a language like Java, but hard to get it right. Why?

Because Object-Oriented programming is more than just writing classes and methods. OO programming is way more than that.

I think the hardest thing in OO programming is the ability to create objects with cohesive functionality. The ability to assign responsibility well is the key to object oriented programming. And that is hard.

To see where you are, ask yourself this question: what is an object? Is it an instance of a class? Or is it a data structure? If any of those two, you don’t think in objects.

I think to truly program in an object-oriented way, you have to treat your objects as a set of responsibilities. Object oriented programming then is creating and assigning responsibilites to different objects. OO programming is creating a set of objects that are able to collaborate to achieve a task.

Also, it’s important to spread the functionalities (more or less) equally to several objects. It’s important to have objects that do several (Grady Booch recommends 3 to 5) of related tasks and do it well: specialized (cohesive) objects. That’s why your classes should not be too large. It is a sign that your class does too much — it has too many responsibilities — if it is large. It’s usually good then to break up that class into more specialized classes.

The biggest benefit of OO, I think, is the ability to think more abstractly. It’s the ability to concentrate on a higher level. It’s like programming in Java vs C++. In Java, you don’t have to worry about pointers and references. You are working on a higher level. I think you can accomplish more that way (and save your brain for other tasks ;-) ).

To be a good programmer, better coder, you have to be a good OO programmer. It’s not an easy thing.

2 Responses to “Thoughts on Object Oriented Programming”

  1. Hoodlum Physicist says:
  2. Stanley Kubasek says:

    Hoodlum,
    Thanks for a great response!
    I’m more of a “craftsman” wannabe. I want to become one by constantly learning, constantly getting better — you summarized it nicely. :-)
    One thing that I like is clean, simple solutions. I work hard to achieve that — I have not seen too many solutions like that in the workplace. And that — making complex things simple — is the hardest part of programming — crafting. :-)

Random Quote

Topics

Tags

Archive

Recent Entries

Currently Reading

Shelfari: Book reviews on your book blog

:: The Pragmatic Craftsman recommends

:: The Pragmatic Craftsman book reviews

Info

© 2001-2010 Stanley Kubasek About me :: Contact me

@PragCraftsman on Twitter

I put Code Complete #1 over Martin's book because it has "awaken" me as a programmer. But other than that, Martin's book is the best! - 11 hours ago@mcory1 First of all, @unclebobmartin is my hero! Agile Software Development, Principles, Patterns, and Practices is my #2. SOLID rules! :) - 11 hours agoWhich programming book has had the most influence on your career? I have to say "Code Complete" by McConnell - 1 day agoI have not used Git myself, but see a lot of good buzz about it. Is this anology accurate: Git is to SVN as SVN is to CVS? #git #svn - 1 day ago