Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

non-cohesive business entities 2

Status
Not open for further replies.

dragonwell

Programmer
Oct 21, 2002
863
US
Adding features to existing application. Need to add a group of properties to business-entity object. Trying to decide if create additional object and use composition or just add new properties to existing object. Reason wondering is this is a very primary object, which gets queried very frequently, but the new set of preperties are not used that much and would be a waste loading them every time.

Say it's a User object. Now we need to add more properties to user that are only used in part of app. Should I just add all the new properties to the User and just accept the performance hit of loading those every time, or create a UserProfile object to contain the new properties and contain this as a member in User?
 
Can the values be loaded as part of the normal construction of the object (IOW, are they just additional columns in tables that you already query)? This would add minimal overhead during construction.

Also - Is this class used outside your system? Are there other systems which depend on it's structure staying identical?

And - How many objects get constructed at runtime? Would adding these new attributes cause significant memory bloat?

Otherwise, you might want to look at specialization or composition.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Dragon,
I would maintain cohesion of the entity and give it behaviors that closely relate to it. Placing the behavior of one object into another unrelated object, only to maintain preformance leads to a muddled domain, code will be difficult to understand.

Also, you spoke of a preformance hit if you add these new properties. You could implement a technique called lazy loading. Lazy initialization is used when certain instance variables are costly to initialize (memory/time) and, may never be used. One method is to initialize the instance variable on demand rather than during instance initialization.

What are your taughts?


 
I agree. The "muddled domain" really struck a chord.

You're right, Chip, they are just additional columns in a query I already run so I suppose the performance hit would be minimal.

I was looking for the easiest way out - thanks for helping me clear my head.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top