Home > Uncategorized > You got your procedure in my object!

You got your procedure in my object!

May 8th, 2009 Scott Lilly

There used to be a television commercial for some candy that had chocolate and peanut butter.  In it, there would be one person walking around with an open jar of peanut butter and another walking around with a chocolate bar.  They would bump into each other and the chocolate would end up in the peanut butter.  The peanut butter owner would exclaim, “You got your chocolate in my peanut butter!”  While the chocolate bar owner would shout, “You got your peanut butter on my chocolate!”  They’d both try this new concoction, declare it an amazing snack, and all of us viewing would go out to buy the candy.

What does all this have to do with programming?  While thinking about how to develop a good framework for the suite of apps I work with, I’ve been looking at what I’ve seen that works and what doesn’t work.  One thing that I see a lot of is procedural code written in object-oriented languages.  We’ve all seen (and probably created) classes with a method that is hundreds, if not thousands, of lines long.  You got you procedure in my object!  But I think the opposite problem can also occur.  When working towards an “ideal” application, you can try forcing procedural processes into objects, handling them with massive event raising or forcing them into place with an implementation of the Chain of Responsibility pattern.  You got your object in my procedure!

One of my thoughts when creating this framework is to have objects (Customers, Jobs, etc.) represented by objects, and have processes handled in procedural methods.  I’ll still be following the SOLID principles, especially Single Responsibility and Dependency Inversion.  However, I won’t be forcing things to use styles that don’t seem to be appropriate.  My next post will go into some detail of how (and why) I’ve set up the projects for the framework.

BTW, as I started writing this, a friend of mine sent me an e-mail with a link to a funny history of computer languages, complete with a reference to the chocolate/peanut butter commercial.  Check out this Brief, Incomplete, and Mostly Wrong History of Programming Languages for a laugh.

Categories: Uncategorized Tags:
Comments are closed.