PMFJI.  Returning a structure in this example is no less encapsulated 
than returning individual field values, depending on how the methods 
are written.  If you want a structure, just write a getter for the 
structure.  I'd recommend a better name, though, such as 
getMemberAsStruct().  In fact, I'd want that method to call 
individual getters within the Member component to get the correct 
data for the structure to be returned.  This protects the component 
for all the same reasons previously discussed as good reasons for 
using getters and setters.

The getAllAttributes() method illustrated in this thread would be 
closer to a "hack" (meaning in this case less encapsulated), since it 
assumes the intent is to simply puke all the fields' data into a 
structure and return them.  However, even this approach doesn't 
really "expose" anything, in that exposition of data means allowing 
an external program to directly refer to attributes, e.g., 
"member.firstName", which this method doesn't do.

1.  Theoretically, all attributes should be returned using getters, 
and set using setters.
2.  Theoretically, all databases should be in Fifth Normal Form.

In other words, "In theory, there is no difference between theory and 
practice.  In practice, there is."

FWIW, that's my view from Theoretical Corner.  Your mileage may vary.

- Jeff

On 18 Apr 2005 at 13:48, [EMAIL PROTECTED] wrote:

> >Why is returning a structure a "hack"?
> 
> You're exposing the internal variables of the object.  I'm not saying don't
> do it absolutely.  I'm doing the exact same thing when in makes sense.
> Just be aware that the preferred method would be to always use getter and
> setter methods to access attributes.
> 
> 
> Jason Cronk
> [EMAIL PROTECTED]
> 
> 
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
This list and all House of Fusion resources hosted by CFHosting.com. The place 
for dependable ColdFusion Hosting.
http://www.houseoffusion.com/banners/view.cfm?bannerid=11

Message: http://www.houseoffusion.com/lists.cfm/link=i:12:6748
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/12
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:12
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.12
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to