Just What IS Abstraction, Anyway?
Consider scenario 1:
It's Saturday, and I have a list of chores to do.
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?
It's Saturday, and I have a list of chores to do.
- Throw the laundry into the washer;
- Do the dishes;
- 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?

