--
You received this message because you are subscribed to the Google Groups "Object-Oriented Programming in ColdFusion" group.
To post to this group, send email to coldfu...@googlegroups.com.
To unsubscribe from this group, send email to coldfusionoo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/coldfusionoo?hl=en.
"session" is merely an implementation detail and there's no guarantee
that current student and current login will always share the same
implementation.
> 1) I don't know if simply inheriting from a session service is the
> best approach. The way of working with inheritance I was always told
> is to use an "is a" approach.
Right. "session service" is, at best, an implementation detail and,
frankly, I'm strongly against scope-based facades since they actually
create global variables and stronger coupling (since all services that
use such scope-based facades now have access to the same *global* pool
of data and are all tied together by that data - whereas previously
they notionally only had access to their own data and were independent
of each other).
> 2) I need to make these methods more generic so more along the
> approach of hasCurrentObject(), set / get CurrentObject() approach.
Why?
You're conflating an implementation detail with your API which is a
bad thing. As noted above, using session scope is an implementation
detail and there's no guarantee you would always use session scope for
all such "similar" things.
Furthermore, wrapping a shared scope with a generic API just adds
overhead for no real benefit:
if facade.hasCurrentObject("name")
x = facade.getCurrentObject("name")
facade.setCurrentObject("name",value)
vs
if structKeyExists(scope,"name")
x = scope.name
scope.name = value
The latter is both easier to read and faster.
You *might* have a good argument for encapsulating the raw storage
mechanism as a private method within the service - assuming you want a
struct/scope-based implementation:
if structKeyExists(getCurrentStorage(),"name")
x = getCurrentStorage().name
getCurrentStorage().name = value
and
private function getCurrentStorage() { return session; }
Now you can modify just one method (in each service) to change how the
current thing is stored but I really don't think it buys you much (if
anything).
I think you're over-analyzing.
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
Yeah. I see scope facades repeatedly in CFML code and it's just plain
ol' wrong. Some frameworks even enshrine this nonsense in their API so
the framework itself is providing you with a completely unencapsulated
GLOBAL variable dressed up in the overhead of a set of method calls.
Dreadful!!
---
James Allen
E: ja...@jamesallen.name
Blog: http://jamesallen.name
Twitter: @CFJamesAllen (Coldfusion / Web development)
Twitter: @jamesallenuk (General)
Twitter: @JamesAllenVoice (Voiceover)
--
Yes, preferably with the actual storage isolated to a single private method.
It's easy to test - either by extension and overriding or by method injection.
It isolates the variables - there's no global facade that provides
access to all session variables (or client variables or whatever).
It keeps variables independent in terms of storage - you can change
how an individual variable is actually stored, without worrying about
affecting other variables.
It encapsulates what is actually stored - this is important in the ORM
world where you need to be careful about detached objects (which you
get when you store _objects_ in session scope rather than just their
PKs). getCurrentUser() can / should encapsulate that: by relying on
the PK in session scope and fetching the object on demand per request
(Hibernate caches it anywhere per request - or, more accurately, per
Hibernate session).
The "SessionFacade" is a monstrous antipattern, IMO, particularly in
CFML. Unlike many languages, CFML provides long-lived scopes that span
multiple requests. Wrapping such global scopes in a bean doesn't
encapsulate anything (especially if it's actually called SessionFacade
- because then you still have "session" all over your app!). A scope
facade creates overhead on the global scope without adding any access
control - so any code that has the scope facade injected can access
*any* of the variables in that scope, just by calling methods. Other
languages that don't have these long-lived scopes have to create
abstractions, services and facades in order to provide an API that
does what CFML offers out of the box.
It's similar to all the nonsense I see about the Singleton pattern.
It's complicated in Java because Java has worked so hard to remove
global variables, but singletons are exactly that: global variables.
CFML provides a single, thread-safe point for initializing singletons
- onApplicationStart() - and a "global access" method, namely
application scope. CFML has near-zero-ceremony singletons built-in!
---
James Allen
E: ja...@jamesallen.name
Blog: http://jamesallen.name
Twitter: @CFJamesAllen (Coldfusion / Web development)
Twitter: @jamesallenuk (General)
Twitter: @JamesAllenVoice (Voiceover)
-----Original Message-----
From: coldfu...@googlegroups.com [mailto:coldfu...@googlegroups.com]
On Behalf Of Sean Corfield
Sent: 03 November 2010 19:59
To: coldfu...@googlegroups.com
Subject: Re: [coldfusionoo] Re: Refactoring - How would you approach this?
--