From: P. F. <fl...@us...> - 2002-01-30 05:31:45
|
Hum. To be OO, I would model the "Group of Users" as an object. This is typically the entity returned by the Group class. Then, the User class can also retrieve the users specified in that object "Group of Users". The Group class fetches the uid of the users, puts them into the object. It does not need any user info. The User class fetches the User info for each users, puts this into the object. It does not need any group info. Having a suitable API to the GroupOfUsers, the User class can get enough info to minimize the number of accesses to the DB. The GroupOfUsers would simply be a smart Array I guess. Now, how you turn this into Mason code, hehe, that's up to you :-) Just my 0.02Euro contrib... --Pascal Tobias Kremer :: IT wrote: > Hi list, > > I have been fighting with this problem for some time now and > finally decided to ask you for a solution. > > Assume I have a class User which represents my usertable. > Furthermore there is a class Group which maps to a > group-table containing references to users. > > The class "User" has a method "retrieve_by_attribute" which > fetches a specific user. The class "Group" has a method > called "get_members" which returns "User" objects for all > users in the specified group. > > To keep the object oriented approach clean the method > "get_members" selects all uids associated with a specified > group and afterwards calls "new User()->retrieve_by_attribute()" > for every row returned by the database. This of course > triggers one database select for every user returned by > the first select which produces quite a lot of load on the > database. > > One way to get around this is to provide a method "get_user_collection" > in class User which receives an array and returns userobjects > for all userids in the array. But to my mind this is not what > object-orientation is about. > > Doing a joined select in class "Group" is also unwanted because > I would have to mix user attributes with group attributes thus > ending up in fixing two sources if applying changes to the database. > > Is a caching mechanism the only way to keep it strictly > object-oriented or is there another way to do it ? How do you > solve this problem ? > > Thanx! > > > > urbia Grüße - best regards > > Tobias Kremer > Webmaster / Software-Entwicklung > > urbia.com AG > Hohe Str.115, 50667 Köln > > tel: +49 (0)221 - 2949 154 > fax: +49 (0)221 - 2949 599 > e-mail: tob...@ur... > > http://www.urbia.de - we are family > http://www.urbia.fr - votre espace famille > http://www.urbia.co.uk - the family site > > "Linux is like a wigwam. No gates, no windows > but an apache inside" > > > _______________________________________________ > Mason-users mailing list > Mas...@li... > https://lists.sourceforge.net/lists/listinfo/mason-users |