Hal Helms - Real World Object Oriented Development, Sarasota - Day Two

Posted February 25, 2009 at 12:27 AM by Ben Nadel

Tags: ColdFusion

I just have time for a really small post today because I spent the time after class hanging out pool side talking about indexing strategies, frameworks, high resolutions drum scans, ColdFusion 9, scalability, how to open beer bottles with just about anything you can find on your key chain, and host of other fun topics. Then, after that, Charlie Griefer and I spent some time discussing "what it means to be deck of playing cards." All in all, it was a great evening with some great people.

But, the day concerned more than just how many things Steve has deep fried is his kitchen (and frankly, after he mentioned a deep fried McRib sandwich, I am not sure I could have taken much more). For me, there was one really great break through for the day. The break through itself is so obvious once you step back and think about it; but, until you do, not thinking about it can add a lot of mental stress and confusion.

The break through was in regard to the Open-Close principle. This principle states that an object should be open to extension, closed to modification. The idea here is that if you find yourself having to open up code every time you want to add new functionality, then the things you are changing should probably be factored out and encapsulated somehow. All to say, the code should be closed to direct modification, but open to extensions in functionality through other means (such as sub-classing and strategies).

The Open-Close principle is definitely one that feels right and makes a lot of sense. But, if you don't fully know where to apply it, then you can start to doubt your architecture every time you need to make updates. My breakthrough was when Hal stated that the Open-Close principle applied only to the Domain Model and that is has nothing to do with the UI (user interface) or the Controller layers.

Now, if you stop and think about that comment, obviously it has to be true; I mean, if you add functionality to an application, then it necessitates that you update your UI and your Controller layer to accommodate that new functionality. But the breakthrough that was afforded by the explicit recognition that changing the Controller layer was OK is that it was also OK to update logic that surrounds sub-class selection. By that, I mean that at some point, somewhere, some logic is going to need to decide which sub-class to instantiate for a given reason. And, if creating new sub-classes is a way for us to extend code rather than modify it, we'll still need to modify some code to handle the new sub-class selection. All to say that while the Open-Close principle is excellent, modification to code does need to take place and is not necessarily an indicator that your architecture is flawed.

 
 
 
 
 
 
Hal Helms - Real World Object Oriented Development - Sarasota, Florida. 
 
 
 
 
 
 
 
 
 
Hal Helms - Real World Object Oriented Development - Sarasota, Florida. 
 
 
 



Reader Comments

Feb 25, 2009 at 1:03 AM // reply »
153 Comments

Interesting. So how do you reconcile that with duck typing?


Feb 25, 2009 at 1:08 AM // reply »
153 Comments

Blarg. This is why you don't comment at 1am.

When I said "duck typing", I meant to say "method injection". I have no idea why it came out the other way.

Cuckoo.


Feb 25, 2009 at 12:30 PM // reply »
116 Comments

Hi Ben, sounds like you, Hal and Clark are having a great time so far!

First, just to be pedantic, it's the "Open-Closed" principle. ;-)

In terms of obeying this principle, I think that, like all OO principles, it's a guideline. It's not like the OO police will come shoot you if you modify a class heh. But the idea is to minimize it as much as possible, as well as ensuring that any single change that IS needed is localized to ONE place.

This is where something like factories can be very helpful, as I'm sure you know. That way, if you add a new class, the change should be limited to the factory since it is the only class that should have type coupling to the classes being created. And if you can go even further and extract this knowledge into metadata, you can actually make changes like this without touching the actual code at all, just by changing an configuration file or IoC container. As always, it depends hehe.

Keep posting, I am enjoying reading about how this is going! Thanks.


Feb 25, 2009 at 1:45 PM // reply »
11,246 Comments

@Rick,

I am not sure that method injection is necessarily any different than something like sub-classing. Obviously they are very different in their expression, but in a way, they are both techniques that can be used to extend a class in somewhat dynamic ways. That said, whether you are injecting something or sub-classing something, the calling code still needs to be able to choose what action to take. That is, either a sub-class or an injected entity needs to be selected; so, as those set of sub-classes and the set of injected identities grows, the Switching or IF statements or whatever needs to be updated in the calling code.

@Brian,

Absolutely, I agree with you. I think one of the pitfalls that new OOP disciples fall into is that each rule is golden and when you break it, there's a problem (I know I have falling into that many times). The beauty of what Hal said was not so much that it was very insightful (not to demean it in any way) - the beauty was that is was a slap in the face with reality :)

I definitely like the idea of a Factory handling logic like this. Also, if you don't have any IoC framework, I would be comfortable with the Controller making these kinds of decisions so long as you don't start to repeat the logic in multiple places.


Feb 26, 2009 at 3:20 PM // reply »
27 Comments

I was just thinking about the Open-Closed principle as I contemplated making some edits to an object. I think the question for me would be when is an object done and considered to be "closed". Be it right or wrong, some web apps are never considered finished and are notorious for having new functionality added after deploying. When a new feature comes up, it would have to be a balance between keeping the original object closed to modification and not creating too many extensions (i.e., maintenance headaches).


Feb 26, 2009 at 6:15 PM // reply »
11,246 Comments

@Matt,

I'm still trying to get this stuff. Obviously, if things need to be changed, they need to be changed; but, I suppose the point is that you want to architect extensibility in as much as possible so that when you need to make changes, the number of places you need to change can be minimized.


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 23, 2013 at 6:06 PM
The Girl Who Broke My Heart, And Made Me A Better Person
Good day,ladies and gentle men, my name is Dr AMADI the great spell caster in Africa, i have help so many people for different kind of problems,who say there is no solution to problems on earth, that ... read »
May 23, 2013 at 4:26 PM
ColdFusion QueryAppend( qOne, qTwo )
@Heather, Glad people are still getting value out of this! ... read »
May 23, 2013 at 3:49 PM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@WebManWalking, I meant the code at the bottom (not the video). I did try to experiment with an intermediary variable, like: value = users.id[ i ]; arrayContains( userIDs, value ); ... but t ... read »
May 23, 2013 at 11:06 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben, Are you talking about As Number: YES As String: YES As Java: YES? If so, that's with 3 different ways of referencing the constant 1, not users.id[1]. Query object references(*) are what seem ... read »
May 23, 2013 at 9:55 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Dan, According to the CF Admin, I'm running Java "1.6.0_45". As far as the DB column, in the database it's an INT. I'll see if I can dig into what CF sees it as. @WebManWalking, But h ... read »
May 23, 2013 at 9:49 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben, I think the problem is that we're used to loose typing in ColdFusion, like JavaScript. If a value is a number but it's needed in an expression to be a string, noooo problem. I've encountered ... read »
May 23, 2013 at 9:47 AM
ColdFusion QueryAppend( qOne, qTwo )
You rock! Thank you, thank you, thank you!!! ... read »
May 23, 2013 at 5:19 AM
Ask Ben: Print Part Of A Web Page With jQuery
How to print also the background color of table cells and table lines ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools