The Register® — Biting the hand that feeds IT

Feeds

Coupling and the power of accidental relationships

Emergent Design: break point

  • print
  • alert

Customer Success Testimonial: Recovery is Everything

Book extract, part three In the third extract from his book, Emergent Design: The Evolutionary Nature of Professional Software Development published by Addison Wesley, Scott Bain tackles the complex issue of coupling, and looks at how unnecessary complexity can be injected through accidental or bad coupling.

Coupling is a general term that describes the situation where one part of a system affects another part of the system in some way. Often, in object orientation, we are talking about two classes - classes are coupled to the other if a change in the second class will cause a change (or a need for a change) in the first. Coupling is usually spoken of in terms of it being a problem, but in fact coupling is not bad in all cases.

In fact, some coupling is absolutely necessary, since a system with no coupling would not be a system at all. Coupling, in the good sense, is how individual objects are combined to create the overall system. We do not want coupling that:

  • We did not intend
  • We did intend, but we do not actually need

Intentional coupling versus accidental coupling

Bad coupling is usually termed tight coupling. Logical, necessary, helpful coupling is called loose coupling. Loose coupling is ideal; tight coupling is to be avoided.

I am not wild about these terms, frankly. For one thing, they do not stick in my mind, and I always forget whether loose or tight is the bad one. They both sound bad, in a way loose things fall apart and tight things are hard to take apart and change.

My point is that part of what we are doing in promoting software development as a profession is getting terms like this more clearly defined, and to make sure they inform what we do.

To me, good coupling is coupling I (or you) put into the system on purpose, to achieve an end or solve a problem. The coupling that seems to "get me" is the coupling that I did not realize I had because it crept into the system without any intent on my part.

So, I use the terms "intentional" for good coupling and "accidental" for bad. It is not difficult to remember that accidental is bad - just think of a car wreck.

Coupling can occur at any level, from the code within a method to the architecture of the system overall. It can even occur in your driveway, as I shall explain.

Driveway coupling

I bought a new car a few years ago.

The next morning I went out to my car, got in, and started it. Once it was running, I tried to put it into reverse gear, but it would not go. The lever that selects from park, neutral, drive, and reverse would not move from park to reverse.

I was disappointed, and I called the dealer to explain the problem I was having. "Ah, yes, that always happens," he said. This was not what I wanted to hear. I had selected a car model that routinely broke its transmission? That was not what he meant. "People are always confused about this model... and we always forget to tell them for some reason. To put that car into gear, you need to put your foot on the brake."

Okay. So it would not have gone into drive or neutral either, since my foot was not depressing the brake pedal. I did not know that because I was not trying to go into anything but reverse (this is one reason beta testing is so difficult to get right). I was on a cell phone, so I tried it while the dealer was still on, and it worked.

"We sometimes just put our foot on the brake naturally when we start the car, so sometimes people do not run into this for a few days," he went on, "but invariably someone will call, within the first week, and report a failed transmission." "Why did they engineer it this way?" I asked. The designer in me was curious.

"It is to make sure your foot is not on the gas. People use their same foot for the gas and the brake, so if the foot is on the brake, it is not on the gas." he explained. That seemed to make sense.

But later I began to think. Why didn't they just hook up a sensor up to the gas pedal? I may or may not put my foot on the brake when I go into gear, but I certainly will not be accelerating at that point. In fact, that was the concern - that I not put the car into gear while revving the engine.

Regcast training : Hyper-V 3.0, VM high availability and disaster recovery

Latest Comments
Anonymous Coward

Foot on Brake = good. Detection mechanism bad.

As pointed out, the need to have the brake applied when taking an automatic transmission out of park is self evident.

However, I myself have been the victim of a poor implementation of this necessary and desirable coupling.

In my case, the braking system was fine, the automatic transmission was equally fine, but the micro-switch that detected that the brake pedal had travelled (i.e. was applied) developed a fault.

The result: I could not get my vehicle out of park, even WITH the brake applied.

The intent is of course to ensure that the transmission is not taken out out of "Park" without the brake being applied. The implementation only achieves this as a side effect. What the implementation ACTUALLY ensures is that the brake pedal has been pressed AND that the brake pedal microswitch is functioning.

As well as my annoying predicament (when the fault developed we were in a public refuse disposal depot/waste transfer station having just unloaded a load of rubbish), it is possible, as a result, that in the event of a brake system failure the system will permit "Drive" to be engaged, as long as the brake PEDAL is travelling and the microswitch is working.

I doubt that there is not a more reliable mechanism by which the intended coupling could have been properly achieved.

I also doubt that such a mechanism would be as cheap or easy to implement.

In the rush to "deliver" the feature, the implementation incorporates a compromise that ultimately renders the feature not just imperfect but actually dangerously flawed. Dangerous to the extent that it might lead to injury or even loss of life.

It's a shame that this article missed this opportunity to highlight the hidden cost of saving costs at the wrong stage of the project lifecycle.

0
0

Ping to "amanfromMars"

if "You were a Carpenter and I was a Lady"

and i asked "How do I become a Man and start my Building of such things?"

you would Reply "xxxxxxxxx?"

0
0

@Bruce and @Robert

Whilst I disagree with Bruce's tone (easy to misinterpret in text), I can't disagree with his points, or how they interfere with his analogy. He uses the terms Accidental and Intentional - and this is indeed an intentional 'feature'. Whilst I don't doubt he knows what he is talking about regarding Coupling, if there were any other examples like that in the book I'd get too annoyed with it to gain anything from it. Character flaw on my part? Certainly, but I doubt I'd be alone.

And regarding the foot on a brake and pedal at the same time - as far as I know the only people who regularly do this are racing drivers, who tend not to use automatics in the first place.

</ friday_afternoon_pedancy>

0
0

More from The Register

SCO vs. IBM battle resumes over ownership of Unix
Zombie lawsuit back and wants to suck the brains out of Linux
Bjarne Again: Hallelujah for C++
Plus: Now officially OK to admit you never used STL algorithms
Interwebs taunt Sir Jony over Apple eye candy makeover
Hey Ive, Ive... add more unicorns, willya?
Apple: iOS7 dayglo Barbie makeover is UNFINISHED - report
Plus: You don't like the icons? Blame marketing
Red Hat to ditch MySQL for MariaDB in RHEL 7
So long, Oracle! Don't let the door hit you on the way out
Shy? Socially inadequate? Fiddling with your phone could help
App 'tells the brutal truth' about social inadequates' chatup lines
Java EE 7 melds HTML5 with enterprise apps
New release arrives with GlassFish, NetBeans support
 breaking news
'Office Facebook' firm Tibbr wants you to PAY for mobe-meetings app
Great idea. Punters won't cough for it though
 breaking news
The only Waze is Google: Ad giant tipped to gobble map app 'for $1.3bn'
Pac-Man-satnav-ish upstart in bidding war with Apple, Facebook
 breaking news
PM Cameron calls for modern, programmable computers! (We think)
IT education musings to G8 chiefs to mystify IT industry