Thursday, June 28, 2012

Nick Burns the Client Object

In 2009 I compared a lack of data encapsulation to a nudist community. Not long ago another metaphor struck me, but this one applies to the interactions among objects within that anti-pattern: Nick Burns, Your Company's Computer Guy. If translated to the form of skit dialogue, it might be like the following.
  • Nick Burns, Client Object: (impatient) You're the Customer object, right? Tell me the average number of purchases per month, year-to-date.
  • Customer Object: (confused) Er...but...I don't have a method for doing that. I know the customer inside and out, but you're asking for statistics about the orders. I suppose I have the ability to fetch all customer purchases for a time range...
  • Client Object: (annoyed) Don't know much, do you? Give me all your data and MOVE! The Client Object .gets() all the information from the Customer Object, filters it, and finally calculates. THERE! Was that so hard?
  • Customer Object: (defensive) Well, if someone had given me the capability to do what you were asking, or if you had gone to the right Object in the first place...
  • Client Object: (dismissive) Don't worry about it. You're just one more do-nothing data container like all the objects in the hierarchy. I'm here to do your thinking for you. The Client Object starts to return to its caller, then hesitates and turns back to the Customer Object for one last bit of sarcasm. Oh, by the way, you're welcome!

No comments:

Post a Comment