Skip navigation

OO is Hard

Andres Taylor via Jeremy Miller:

Maybe it’s just me, but coming from Computer Science class I thought that OO was easy. I mean, how hard can it be to create classes that mimic the real world? It turns out that it’s pretty hard. Ten years later, I’m still learning how to model properly. I wish I spent more time reading up on OO and design patterns. Good modeling skills are worth a lot to every development team.

This is his top item in a great post, “Top ten things ten years of professional software development has taught me.”

OOP is hard. Hard as in difficult to do well. More appropriately, as Andres puts it, it’s “harder than you think”.

As a technique it’s deceptively easy to think you have it mastered. On the surface it makes a lot of sense. There’s an initial learning curve: what’s inheritance; what’s information hiding; what’s polymorphism? Once you’ve gotten these concepts it’s easy to be lulled into a false sense of accomplishment thinking you have mastered the technique: “I get OO!”

Did you really get it the first time you made that or a similar proclamation? I know I certainly didn’t. Rather it was a series of accelerating “Aha!” moments that continue to this day.

Question:

How many procedural programs are masquerading as object oriented ones? That is, how many developers think they’re writing OO apps but aren’t?

A) Lots of them
B) Loads of them (for the English)
C) All of the above

I’d wager C.

There is a lot of code in the wild which is simply “structured procedural.” That’s fine, but, I’m comfortable guessing based on past and anecdotal evidence, the author is usually under the impression that what they’re doing is true OO.

Why Bother?

I believe OOP is a superior way to structure your programs because it encourages direct mapping between your software and its problem domain. A good OO program is an executable model of what your domain, and, as Scott Bellware argues, superior to model-by-wire techniques favored by the old school, disconnected, ivory tower software architects.

Central to the point of DDD and the trend toward Domain Model is the question, why would you separate your model from it’s implementation? There simply is no need for the separation when you’re doing OO the right way; the model is the code is the model is the code…

Increasing Returns

Becoming proficient with OO is a big investment. It’s a change in mindset that comes with a learning curve, and flattening this curves takes plenty of time, effort, and practice. It’s a change in mindset that requires a constant commitment to learning.

As an investment, consider OO an annuity, and more of a permanent life insurance than a trust fund. That’s to say you’ve got to put work in to get benefit out. There’s a lot of reading you need to do and a lot of decisions and mistakes you’ll need to make before you develop a trusty toolbox of strategy and tactics. 

Infrastructure technologies come and go. Even large scale shifts in our tool approaches such as functional programming and external DSLs work perfectly well (or at all) when an OO lens is applied.

There is no other development paradigm (I’m aware of) has either the level of utility and nigh-universal applicability or the vast body of knowledge behind it: Agile Methods, Refactoring, TDD, DDD, Patterns, Pattern Languages - all “pluggable knowledge” into the OO mindset. OO techniques and practices form a fabric and amplify each other, they evolve.

5 Comments

  1. Posted March 25, 2007 at 11:51 am | Permalink

    Damn. You hit the nail right on the head. A while back when I worked for “the big insurance company in town”, I ran into the same “structured procedural” programming (I guess that’s what happens when you take a ton of COBOL developers and put them through a 1 hour Java tutorial…)

    But if you recall our conversation about how it takes at leat 7 “classes” to map your domain entities, your statement holds true. It’s sad that people shy away from it due to it’s “complexity”…which I think it’s not really that the problem is “complex”, but rather that they’re lazy.

    A while back, I ran into this blog post by Harry Pierson: http://blogs.msdn.com/devhawk/archive/2005/10/05/477529.aspx

    You should check it out.

  2. Dave
    Posted March 26, 2007 at 9:05 am | Permalink

    Hey Javier. Thanks for the tip, I’ll check it out.

    I wouldn’t necessarily say lazy (though there is that problem out there.) I’d be more inclined to point a finger toward lack of knowledge or a tendency to look for the “silver bullet” with all of this new knowledge you’ve accumulated without realizing you’ve got a ways to go.

    (Cough, CSLA, cough.)

    I think the best thing a team using OO can have is a veteran. I think the same is true for a team making a foray into Agile.

  3. Posted March 26, 2007 at 3:30 pm | Permalink

    hear, hear!

    CSLA…hmm…what are your thoughts on that?

  4. Dave
    Posted March 27, 2007 at 10:03 pm | Permalink

    My opinion (humbly) about CSLA: I’m opposed to the idea of Mobile Objects. I don’t like the false sense of reuse it gives you. Accessing or hydrating an object locally or remotely can be quite a significant difference you might not want to make implicit. You are likely to still end up with differing local/remote use cases. The industry is trending toward services where you’re dealing w/ messages in and out. I like the notion of “the endpoint is the application.”

    That said, it’s a pretty complete default architecture and those are few and far between. So, for me, it was worth study and evaluation. It probably works great in a client-server-esque, single application scenario.

    I am not opposed to a “Governing Metadata Layer” for entities. That is, a layer that will generate entity representations for different purposes: Bindable Client Object, DTOs for Aggregation, DDD-style Entity, JSON arrays, restful XML, etc.

    More on that later :)

  5. Posted April 8, 2007 at 11:55 pm | Permalink

    Once you feel you’ve mastered OO, go pick up a copy of Analysis Patterns by Fowler, and be prepared to take another step backwards from what you *thought* you knew. The learning curve gets bigger and bigger the more you read, but it is turning out to be quite rewarding. Fowler’s book on Object Oriented Analysis Patterns inside the domain model is quite a cool read.

One Trackback/Pingback

  1. [...] OO is Hard [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*