If Brian Kotek was on the Model Glue list, he'd point out there is value in
abstracting the scope out. Mostly because accessing the scope directly makes
the component harder to unit test. If the scope is abstracted into a
composed object, that composed object can be swapped out for testing and
life would get much easier.

Having done Lots of Unit Tests for ModelGlue, I can see his point.

So if you intend on doing unit tests (a good idea in a lot of cases) you
might try to test your components and see if the hard coded scope gets in
the way or not.


I think the Gold in my (and James's) approach is the object touching the
scope does so internally and no one has/needs to know where the value comes
from.

currentUserLoader simply loads the current user. It may use cookie, session,
client, request, or any other scope that I please. Architecturally, I made
the decision to charge a single component with the intimate knowledge of how
to figure out the current user and retrieve it. This means other code is
free from having to know anything beside knowing when they tell the
currentUserLoader to load(), the returned object is a User object populated
according to the state of the user and application at that moment.



Architectural decisions are always about managing tradeoffs, remember. Sure
all glass fronted sky scrapers look good, but if you live in an earthquake
zone, does it make sense?










On Tue, Jul 21, 2009 at 7:42 AM, James Allen <[email protected]>wrote:

>  Yeah this is pretty much what I do. I definitely prefer the contextual
> approach rather than abstracting the scope.
>
>
>
> ---
>
> James Allen
>
> E: [email protected]
>
> Blog: http://jamesallen.name
>
> Twitter: @CFJamesAllen (Coldfusion / Web development)
>
> Twitter: @jamesallenuk (General)
>
>
>
> *From:* [email protected] [mailto:[email protected]] *On
> Behalf Of *Dan Wilson
> *Sent:* 21 July 2009 12:38
>
> *To:* [email protected]
> *Subject:* [Model-Glue] Re: Accessing session scope
>
>
>
> I tend to abstract retrieving the entity rather than the scope.
>
> For example, I have a currentUserLoader that accesses the session directly
> and eventually returns a populated user object, or a blank one.
>
> I may also have a shoppingCartLoader that does something similar thereby
> returning the cart from session, or client or whatever.
>
> I often find that the entities and the storage needs of those entities
> change independently. For example, I just refactored an application recently
> and put the userID in cookie scope and the cart in client scope.
>
>
> DW
>
>
>
>
>
>
>  On Tue, Jul 21, 2009 at 6:45 AM, James Allen <[email protected]>
> wrote:
>
> That is a good point. So far I’ve only really tried the method I currently
> use which is to encapsulate session access within the relevant service.
>
>
>
> It has proven to be very useful though as when I needed to stop storing the
> user object in session and change to only storing the ID the change was
> quick to make and no other changes were needed in the entire application. I
> like the fact that this is held within the service that it relates to – so
> it’s really easy to locate the functions at a later date.
>
> I also use this method with cookie access. I have a function called
> getCurrentStoredUser() and setCurrentStoredUser() which utilises the cookie
> scope.
>
>
>
> I can’t see any real downsides in this approach to be honest, but as always
> would be interested in hearing how other people handle it.
>
>
>
> ---
>
> James Allen
>
> E: [email protected]
>
> Blog: http://jamesallen.name
>
> Twitter: @CFJamesAllen (Coldfusion / Web development)
>
> Twitter: @jamesallenuk (General)
>
>
>
> *From:* [email protected] [mailto:[email protected]] *On
> Behalf Of *Nando
> *Sent:* 21 July 2009 11:39
>
>
> *To:* [email protected]
> *Subject:* [Model-Glue] Re: Accessing session scope
>
>
>
> Perhaps it might be useful to present the argument as to why encapsulation,
> or which approach to encapsulation, is preferable, from your experience. I'm
> still on the fence with this one and would be interested to hear what
> benefits or drawbacks others have encountered.
>
> Nando
>
> On Tue, Jul 21, 2009 at 12:34 PM, James Allen <[email protected]>
> wrote:
>
> Aha, yes the classic session facade vs direct access via the model debate.
> J
>
>
>
> I access the scope directly but only from those two functions. I prefer
> this idea instead of using a facade as it’s just as easy to go into my two
> accessor functions and change how the data is accessed as required. It’s
> also nicely contextual as it’s handled by my userService – so everything is
> in one place. As long as it’s encapsulated it’s ok with me..
>
>
>
> ---
>
> James Allen
>
> E: [email protected]
>
> Blog: http://jamesallen.name
>
> Twitter: @CFJamesAllen (Coldfusion / Web development)
>
> Twitter: @jamesallenuk (General)
>
>
>
> *From:* [email protected] [mailto:[email protected]] *On
> Behalf Of *Chris Blackwell
> *Sent:* 21 July 2009 11:30
> *To:* [email protected]
> *Subject:* [Model-Glue] Re: Accessing session scope
>
>
>
> but are those two methods in your userService directly accessing the
> session scope or are you using a facade?
>
>
>
> [can of worms] *pop*
>
>
>
> 2009/7/21 James Allen <[email protected]>
>
>
> Hey there Gavin,
>
> What I do with accessing these kind of scopes is I encapsulate the access
> within my model. The best example of this is when accessing the current
> user
> which is stored in session. Within my UserService I have two methods:
> getCurrentUser() and setCurrentUser(). These two methods are the *only*
> place where the session scope is accessed relating to the user object. I
> like this method as it means that if I ever move from session to client I
> can make the change in those methods and the entire application will
> continue to run as it should without any other changes needed. It was also
> really cool when I needed to change from storing the user object itself in
> session to only storing the ID. Once again I only had to make the change in
> one place.
>
> So basically I recommend encapsulating scope access as much as possible
> inside the model.
>
> Cheers,
> James.
>
> ---
> James Allen
> E: [email protected]
> Blog: http://jamesallen.name
> Twitter: @CFJamesAllen (Coldfusion / Web development)
> Twitter: @jamesallenuk (General)
>
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On
> Behalf Of Gavin Stewart
> Sent: 21 July 2009 09:46
> To: model-glue
> Subject: [Model-Glue] Accessing session scope
>
>
> Hello there,
>
> I am a newby to model glue and was just wondering if is best practise
> to access the session scope in controller.cfc or is there a way to
> pass it in?
>
> Cheers,
> Gavin
>
>
>
>
>
>
>
>
>
>
>
>
> --
>
> Nando M. Breiter
> The CarbonZero Project
> CP 234
> 6934 Bioggio
> Switzerland
> +41 76 303 4477
> [email protected]
>
>
>
>
>
>
>
>
> --
> “Come to the edge, he said. They said: We are afraid. Come to the edge, he
> said. They came. He pushed them and they flew.”
>
> Guillaume Apollinaire quotes
>
>
> >
>


-- 
“Come to the edge, he said. They said: We are afraid. Come to the edge, he
said. They came. He pushed them and they flew.”

Guillaume Apollinaire quotes

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "model-glue" 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/model-glue?hl=en

For more about Model-Glue, check http://www.model-glue.com .
-~----------~----~----~----~------~----~------~--~---

Reply via email to