Doug's Resume
OO Lexicon
Chat with Doug!
Recent Entries
You may also be interested in...

heaters
hotels boeken in 7 sec
Engagement Rings
Online Dating Australia




SURF'S UP!
You:
Your Web Site:
<< July, 2008 >>
SMTWTFS
12345
6789101112
13141516171819
20212223242526
2728293031
Search Blog

ColdFusion Jobs
Recent Comments
Categories
Archives
Photo Albums
Funnies (5)
Family (3)
RSS
Reciprocal Links

Powered by
BlogCFM v1.11

27 March 2007
Just What IS Abstraction, Anyway?
Consider scenario 1:

It's Saturday, and I have a list of chores to do.
  1.  Throw the laundry into the washer;
  2.  Do the dishes;
  3.  Scoop the cat poop out of the litter box;

So, I take the laundry out of the basket in my closet and put it into the washer. I dump in one cup of SudSoClean, set the temp to warm, set the load size to medium, and start the cycle.

Next, I move all the dishes out of the sink and onto the counter, wash out the sink, put the drain-stopper in, and fill it with hot soapy water. I put the silverware in first so it can soak the longest, then the plates, and lastly cups. As I wash a dish, I rinse it in the other side of the sink under warm water, then set it on the towel to drain while i finish washing the rest of the dishes.

Saving the worst for last, I get a plastic bag from the kitchen drawer and take it to the cat litter box. I get the plastic strainer scooper thingy out of its container, remove the lid to the litter box, and start scooping out little cat tootsie rolls and putting them into the bag. When I'm finished, I add some fresh cat litter, put the lid back on the litter box, and slide it back into place.

Whew! That was hard work, wasn't it boys and girls!

You know what. I think I'll abstract my chores by adding something between them and myself: my kids!

Consider scenario 2, with me doing my chores after having abstracted them:

I call out to objBrandon and ask him to do the laundry (<cfset laundrydone = objBrandon.doLaundry()>);

I call out to objLilly to do the dishes (<cfset dishesDone = objLilly.doDishes()>);

I call out to objSarah to scoop the kitty litter (<cfset noMoTootsies = objSarah.scoopLitter()>);

Hey! I'm done with my chores!

Abstraction: removing the actual work from myself and executing it by commanding someone else to do it.

It's easy to see why I'd want to abstract my chores. But in an application, WHY would I want to add yet another layer to what may already be somewhat complex?

Because...the way the actual work gets done just might change, and if I have the work abstracted out to individual objects, making those changes is all done in one place.

As an illustration, consider a change to the process for washing my dishes. Now, instead of doing them in the sink, I give in and allow the new process to be rinsing them and stacking them in the dishwasher. I re-write the routine for objLilly, but my call to her to doDishes(), and in fact, anybody else's call to her for the same does not change. Because we've abstracted that chore, the "business logic" associated with it is entirely encapsulated (contained) and found in one place.

In the context of an application, if we DID follow the advice of a peer and "create an abstraction layer for managing persistent variables (such as session variables)", then when the day came that we found a need to stop storing values in session and switch instead to client variables, we don't have to hunt and peck all over our code for every occurrence where a session var gets set; we need only go to our Persistence object and make the needed changes right there.

Abstraction - it's what's for dinner.

Abstraction - the other white meat.

Abstraction - not such a vague term after all, is it?



Posted by dougboude at 2:11 PM | PRINT THIS POST! |Link | 1 comment
Subscription Options

You are not logged in, so your subscription status for this entry is unknown. You can login or register here.

Re: Just What IS Abstraction, Anyway?
In my house, we try not to do the dishes and the laundry at the same time.
The logic is up to us "I better wait to do the dishes until after the laundry is done", or more importantly "I better not start the laundry while my spouse is in the shower".

But it would be nice to have a safety feature in place so that the laundry wouldn't start if the shower water were running.
Posted by psenn on March 28, 2007 at 7:39 AM

Name:   Required
Email:   Required your email address will not be publicly displayed.

Want to receive notifications when new comments are added? Login/Register for an account.

Time to take the Turing Test!!!

What letter comes two place(s) after the letter T?
Type your answer exactly three time(s) in the designated box.

Type in the answer to the question you see above:

Your comment:

Sorry, no HTML allowed!