Setting up my classes

Setting up my classes

Old forum URL: forums.lhotka.net/forums/t/2138.aspx


ballistic posted on Saturday, January 13, 2007

Hello,

I’m working on a community site which will allow members to register and interact with other members.

Members will be able to have a buddy list to which they can add and remove other members.  In addition, members will also be able to view the list, but not update an individual “buddy”

Visitors will be able to see the member’s profile, which includes their bio along with the first 5 buddies in their buddy list.  Clicking on “View All” will take them to the entire list of buddies.

I am not sure how to set up the buddy list to accomplish the above requirements.

Should I create the buddy list as an EditableCollection of Child Objects, say, MemberBuddies (based on ProjectResources), which will allow the buddy list to be populated by the member class and shown in the member’s profile page?

Also, do I then need to create another class BuddyList (based on ProjectList) so visitors can view all the member’s buddies when they click on “View All”

And how do I let members add and remove to their buddy list???

As you can probably tell, this is the first project I use CSLA and am basing it on the sample PT project, but I seem to have different requirements than the sample in the book.
 
Any suggestions would be greatly appreciated!!!

- Andy

ballistic replied on Saturday, January 13, 2007

Thinking about it a little more I have another "solution"

Would I be able to have a Read Only Collection, say, BuddyList (based on ProjectList) which would take a memberID as the criteria then the Fetch method would read all of the member's buddies from the DB and load each BuddyInfo (based on ProjectInfo)? This part would be used when a visitor clicks on "View All"

This same class would have a Shared method that would take a DataReader, supplied by the parent class (Member) and loop through it creating the BuddyInfo objects.  This would be used when the a visitor is viewing a member profile. The member class could pull up it's information, along with that of it's children collections and have each child collection load it's children.

Finally, I would create a Buddy class (similar to the Project class) which would be used to add and remove a buddy from the list.  From the example in the book, this class would implement the add, delete and Exists methods of the data portal.  Members would just select the buddy they want to remove from the list (readonly) and then I would be able to tell the Buddy Class to delete itself based on the ID of the selected buddy.

Please let me know what you think of this approach.

Thank you,

- Andy

ballistic replied on Saturday, January 13, 2007

Here is the object model of the last approach I was talking about.

Let me know,

- Andy

 

ballistic replied on Sunday, January 14, 2007

Ok, ok, I went back and re-read some sections of the book and I believe what I want are called "Switchable Objects" (Page 391 in the vb book).

My concern now is that Rocky mentions that using this method "indicates a flawed object model,.. but there are exeptions."

The reason I am using this approach is for performance on the web.  Sometimes I need the member class to load the child buddy list (calling one sproc which gets the member info, plus the list info), and other times I want the buddy list to load itself.

Please let me know if this approach makes sense how I'm using it, or if I should rethink my design and not use switchable objects. 

It's a little scary using such a unique approach (which could mean my approach is flawed) specially since this is the first project in which I use CSLA.

Please let me know if this makes sense for situation.

Thank you,

- Andy

dshafer replied on Monday, January 15, 2007

Andy,

Without getting into the reasons why using switchable objects could hint at design issues, I'd like to propose that you create two separate buddy list classes.  For example, you could create one buddy list class that is to be loaded from it's parent which would make it a child collection of the member obejct.  The other buddy list class could be a "root collection" able to load itself with information directly from the database.

Dustin

ballistic replied on Monday, January 15, 2007

Ok Dustin,

Your idea makes sense and it matches closely to the PTtracker object model.

The only question I have is whether to make the child collection Editable or Read Only.  I think the main benefit of an editable class is the ability to add and remove from the list (which is in memory and then update), however, since this will be a web app, which will be stateless, can't I just have a read only collection and then have a buddy class which would take care of deleting and creating itself to the db?

Thank you very much for your input.

- Andy

dshafer replied on Tuesday, January 16, 2007

Andy,

All of my experience with CSLA and most of my experience with .Net is in the WinForms environment.  Hopefully somebody else can chime in here with an answer that is suitable for the web.

Dustin

Copyright (c) Marimer LLC