Archive for object-oriented programming

Oh OO, thou art a heartless bitch

Posted in Design Issues with tags , , , , , on August 11, 2010 by moffdub

Well, it has finally happened. I am dreaming about defects in our code. Dream in code? Dog, I live dream-in-code every day.

Time for a familiar argument, a familiar decision. You have a blank slate. You must define some data transfer objects for your consumer based on some requirements. You provide an interface that takes in one of these data structures and returns an XML representation of that data structure.

And, for the sake of this discussion, you are using Java’s XMLStreamWriter as your XML framework (I know, I know, there are much more uber l33t ways, but this was the most straightforward and painless way for you in the time-frame you were given).

Simple. SIMPLE. Right?

Option 1

By now, your nudge, your twitch, your instinct is to define an appendTo(XMLStreamWriter) method to each object, which either writes a simple tag or calls appendTo(XMLStreamWriter) on its constituents:

Read more »

When inheritance hierarchies lose their structural integrity

Posted in Design Issues with tags , , , , on February 17, 2010 by moffdub

Let the record show that the number of work days I missed due to inclement winter conditions is zip, zero, nada. So tell Mother Nature to take her power outages and her blizzards and suck. On. That.

Did you really think some crystalized water molecules were going to keep me from my code? Girl, you MUST be crazy.

In fact, a new episode of Nowhere To Run was forthcoming on Saturday, but I succumbed to fatigue and the call of my nice couch/bed at a paltry 9 P.M. I am so old.

Allow me to posit something to you, folks. Suppose this is your nice, beautiful code:

Read more »

Literal Laws

Posted in Testing with tags , , , , on January 27, 2010 by moffdub

My friends, the code gods were watching me last week and filled me with the providence to contemplate test-driven development at just the right time to prepare me for an inter-team bru-ha-ha. The clarity I gained from T.I.N.O. was put to immediate use when explaining to another team why we don’t practice TDD exactly. Objects, I posited, and still posit, are best designed wholistically, because objects rarely exist in a vacuum.

That is the party line here on the Excellence In Programming web-ring, but that doesn’t mean we move on. No. Of course not. Let’s assume that we are total believers in dogmatic, hardcore TDD. That means we follow the three laws:

  1. You are not allowed to write any production code unless it is to make a failing unit test pass.
  2. You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.
  3. You are not allowed to write any more production code than is sufficient to pass the one failing unit test.

We are about to write a little service class that retrieves a data structure from the database, but we will strictly follow the three laws. Pay close, special attention to law #3. I want to see if I can arrive at the same code following these laws, especially law #3, as I normally do by my wholistic, top-down, design-by-code method.

First the test (law #2):

Read more »

Follow

Get every new post delivered to your Inbox.