• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Lightweight vs. Heavyweight objects

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(this is my first post here so I appologize if this has already been discussed before)

I have an app where each user of the app are encapsulated in a User class. The problem is that certain functionality (such as searching for a user) does not require every single attribute of a user. As a result, I'm using objects that are much "heavier" than they should be for certain cases. I could create a LightWeughtUser class to use in these cases, but I'd like something a little more elegant. I don't want to end up down the road (as features are added to the app) with a LightWeightUser, a HeavyUser, MediumUser, etc. Anyone know of a pattern or have ideas on how to solve this? Ideally, I'd like a sitution where I can just "grow" the object as needed. Thanks in advance for any help...just don't want to reinvent the wheel.
[ June 10, 2004: Message edited by: Michael J. Makunas ]
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think an example or two would probably help us to grasp what you need a bit more easily. I'm somewhat puzzled by (for example) whether you are saying that your system has different types of users with different (or optional) information and responsibilities, or whether you are implying that in your application design there is some external processing code which somehow needs to know what is "inside" a user object.

Could you give an example of what your guess at a "light weight" and "heavy weight" user might look like, and tell us a little more about the code that uses them?
 
Michael J. Makunas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I mean by lightweiht vs. heavyweight user objects:

On this web based app someone can log in and serach for other users based on certain criteria (age, location, etc.). The data access layer does the db query and I get back a list of uids. I then use the list of uids to create a collection of ueser object (User user1 = new User(uid)) For the purposes of displaying search results, all I need is first and last name (user1.getFName() and user1.getLName()). But let say that users have a popularity attribute (user1.getPopularity()) that it calculated by some resource intensive algorithm. I don't want to calculate popularity if I don't need to. There may be other attributes that be resource intensive to calculate as well. Different parts of the app may or may not need them, hence varying degrees of "heavyness".

I think I've answered my own question, though. There is no need for the User class constructor to initialize everything. I can just have the constructor do the minimal stuff (first name, last name) and the the call to User.getPopularity check to see if popularity has already been calculated and if not, do the heavylifting itself.

Thanks for your help. I think I was just way over analyzing the problem.
[ June 10, 2004: Message edited by: Michael J. Makunas ]
 
Frank Carver
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad I could help
 
No matter. Try again. Fail again. Fail better. This time, do it with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic