Friday, January 14, 2005

OOPs, part IV: Salt and Peppa

Another metaphor occurred to me a few minutes ago...

Scenario:
I'm at the table eating bland food.

Procedural fix:
Susan, would you pass me the salt?

OO fix:

Use case:
Eater wants salt
Eater salts food
Eater requests salt from person closest to it
Person closest to salt gets salt
Person closest to salt hands it to Jared

Class diagram:

:eater
-------------------
- saltManager: saltManager
-------------------
- getSaltManager: saltManager
- setSaltManager: void
- saltFood: boolean

:saltManager
-------------------
- saltAdapter: saltAdapter
- saltLocation: String
-------------------
- getSaltAdapter: saltAdapter
- setSaltAdapter: void
- locateSalt: String
- dispenseSalt: void
- saltFood: boolean

:saltFactory
-------------------
-------------------
getSaltAdapter: saltAdapter

:saltLocator
-------------------
-------------------
- getSaltLocation: String

:saltAdapter
-------------------
-------------------
- getSalt: salt
- setSalt: void


And now you ask me WHY ON EARTH I went to that much trouble just to locate the salt...

Because, I answer, I now know exactly what I'm doing, I'm not dependent on Susan, and I don't really care where the salt is. I've covered the all the bases in my model of the salt transaction, AND I've abstracted the idea of getting the salt from Susan to a collection of modules.

Now, I can say this:

  1. set Jared = new eater()
  2. Jared.setSaltManager()
  3. Jared.getSaltManager().locateSalt()
  4. Jared.getSaltManager().getSaltAdapter(locateSalt())
  5. - saltManager executes locateSalt(), which transiently executes :saltLocator.getSaltLocation(), and has returned to it "Susan" for step 6:
  6. - saltManager calls saltFactory with the output of #5 as an argument
  7. Jared.getSaltManager().getSaltAdapter().getSalt()
  8. Jared.getSaltManager().saltFood()

And if I want to parameterize saltFood to get finer-grained control over how much salt I dispense, I can simply modify saltFood and the one place that it's called... from saltManager.

I can even... whoa... turn this into a Condiment API, and abstract even further by creating :condiment and setting ketchup, salt, pepper, and so on, into subclasses (inheritance applies because salt IS-A condiment, pepper IS-A condiment, and so on).

Now, if I haven't experienced a condiment before but it's added to my DiningRoom application, I can simply configure a new subclass... say tartarSauce... or I can take a different pattern and create :condiment as a superclass with 2 children named :sauce and :powder, and then make :salt, :pepper, and :pizzaCheese into subclasses of powder, and :ketchup, :mustard, and :tartarSauce into subclasses of :sauce.

It doesn't matter, because I've modeled the process of getting a condiment and applying it to my food. The function is implied in the classes and their properties/methods, and handlers have been created for the transactions that need to occur between the core classes.

Each class is cohesive (highly specialized)
Each class is loosely coupled (not directly dependent on anything else to do it's job)

My model is flexible, and I'm able to easily expand on it by simply repeating the same patterns for each further level of abstraction. AND, if I reach a point where the manager/factory/adapter idea is no longer efficient, I have an unlimited number of other patterns and frameworks from which to choose.

Now, where did Susan go? That girl is always running off... sheesh!

Laterz!

5 Comments:

At February 4, 2007 11:36 PM, Anonymous Anonymous said...

Good day to everyone
Aciphex
Aciphex
http://www.yeshuanet.com/docs/images/Aciphex/index.html
++++++++++++++++++++++
Tramadol
http://www.yeshuanet.com/docs/images/Tramadol/index.html
Tramadol
============================================
Bentyl
http://www.yeshuanet.com/docs/images/Bentyl/index.html
Bentyl
thx to u

 
At February 7, 2007 3:50 AM, Anonymous Anonymous said...

Buenos ))

I discover this searches :
sitemap
http://info-graf.fr/mas/images/smilies/sitemap.html
sitemap
Here is some of them :
map
map of the site
http://eagleinsurance.com.au/images/smilies/sitemap.html
I discover this searches :
sites map
map sites
http://buff.com.au/images/smilies/sitemap.html
----------------------------------
I wait your suggestions ))

 
At February 12, 2007 7:09 PM, Anonymous Anonymous said...

Do you care about you helth??!! )
So why So should we??

Hi


fluoxetine
--------------------------------------------------
fosamax
gris
:::::::::::::::::::::::::::::::::::::::::::::::::
hoodia
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
imitrex
!-!-!-!!-!-!-!!-!-!-!!-!-!-!!-!-!-!!-!-!-!
ionamin
!-!-!-!!-!-!-!!-!-!-!!-!-!-!!-!-!-!!-!-!-!
kenalog
lamisil
--------------------------------------------------
levbid
levitra
_______________
lexapro
lipitor
:::::::::::::::::::::::::::::::::::::::::::::::::
lortab
meclizine
:::::::::::::::::::::::::::::::::::::::::::::::::
meridia
************************************************
mircette
naprosyn
************************************************
naproxen
nasacort
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
nexium
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
nizoral
_______________
ortho
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
paroxetine
:::::;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
penlac
percocet
!-!-!-!!-!-!-!!-!-!-!!-!-!-!!-!-!-!!-!-!-!
phendimetrazine
phentermine
---------------------------------------------------------
prevacid
prilosec
:::::::::::::::::::::::::::::::::::::::::::::::::
propecia
protopic
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
prozac
pyrethrin
--------------------------------------------------
ranitidine
remeron
:::::::::::::::::::::::::::::::::::::::::::::::::
retin
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


PS
It would be great, if you'll post some more info about that pills.. thx
This is my university project )) Thank you for your post;)

 
At February 13, 2007 6:21 AM, Anonymous Anonymous said...

Hello
porn star teen sex teen sexjpg
free teen sex clips http://byronss.com.au/photos/images/smiles/temp/index.html --> youngest teen sex pic
black teen sex party tiny teen sex pic l

 
At February 13, 2007 2:00 PM, Anonymous Anonymous said...

Hi all!
amateur free porn
amateur blog

amateur curve
-->http://info-graf.fr/forum/Themes/default/images/icons/temp/index.html
amateur free sample video
amateur cum

 

Post a Comment

<< Home