Hi Alan,

I've responded in-line below.


On Nov 7, 2007 3:58 PM, Alan Livie <[EMAIL PROTECTED]> wrote:

>
> I have a bean called User that is composed of an Address bean. At the
> moment its a 1:1 relationship.
>
> A factory handles the composition so when I request User I get it
> configured with the Address bean already composed.
>
> My question is in 2 parts:
>
> 1) When I want to get and set properties of the Address bean from
> client code should I
> a) use objUser.getAddress().setCity("Dundee") or
> b) should I have setters in the User object that delegates to the
> Address object ie objUser.setCity("Dundee") and in User.cfc have the
> method setCity() doing variables.objAddress.setCity()
>


Let the Law of Demeter be your guide:
http://en.wikipedia.org/wiki/Law_of_Demeter

It says you should go for option b, if I understand it correctly.  However,
I seem to have a slight preference for option A at times, and I can't recall
when it has brought me trouble.  I assume it has brought trouble to someone
at some time or another, because we wouldn't see a Law of Demeter otherwise,
but following it blindly is like the story of the angry monkeys:

A few monkeys were put in a room with a stepladder and a banana that could
only be reached if the monkeys used the stepladder. However, when a monkey
would climb upon the stepladder, all the monkeys would be doused with water.
Then new monkeys were introduced and when *they* tried to use the
stepladder, the other monkeys would get angry and beat him up. Eventually,
the room contained none who had been doused with water, but the monkeys who
had been beat up for using the stepladder were still refusing to allow new
monkeys to get the banana.



>
> 2) If I want to save the address using a DAO how should I approach it?
> At the moment I have a UserService cfc that calls the save() method in
> the UserDAO. I don't like the idea of UserDAO having to use the
> AddressDAO to save the address as it seems I'm giving it a
> responsibility it shouldn't have. I thought about the service layer
> and would run UserDAO.save() then call
> AddressDAO.save(objUser.getAddress()). This also seems wrong as I feel
> I'm losing the benefits of the composition in the first place by
> calling 2 save() methods in 2 DAO's for the composed bean. Should
> UserDAO itself be composed of an AddressDAO so it is set up in the
> same way as the Beans?
>

I don't know the "proper" way to do this, but I would opt for how you have
it currently.   But, I'm not as into this service thing as I probably should
be, so I fully grant that I may be giving you the wrong advice for your
situation. =)

Regards,
Sam

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CFCDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfcdev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to