Opinions on child structure

Opinions on child structure

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


dmbRedGetta posted on Tuesday, June 24, 2008

Hey guys,

I'm new to CSLA and I'm finally getting back to true OO programming in general and I'm having trouble shifting my thinking back from unstructured asp code.

I'm making a scheduling application where items are scheduled on a given day and have a begin time and an end time (exhilirating, I know).  Items are associated with resources, and can be associated with an unlimited number of resources (1 or more).  I have this coded and working perfectly using the following classes:

ScheduleItemList: ROLB - Used to display a daily schedule
ScheduleItemInfo: ROB - Represents an item on the schedule
ScheduleItem: BB - Allows user to modify item information (description, date, begin/end times, resources)
ScheduleItemResources: BLB - Manages associated resources
ScheduleItemResource: BB - Handles the insert/delete operations of resource associations
ResourceList: ROLB - Used to display a list of resources
ResourceInfo: ROB - Represents a resource

The application also needs to allow users to create schedule items that re-occur based on some frequency (every Monday, Wednesday, Friday, or every Tuesday, etc).  So far, I have created new classes to handle the Template items:

TemplateItem: BB - Allows users to modify template item information (description, begin/end times, resources, recurring days)
TemplateItemResources: BLB - Manages resoures associated with template item
TemplateItemResource: BB - Handles the insert/delete operations of template item resources

A template item can be created independent of any existing schedule item, or (for ease of application use) one can be created by simply marking a schedule item to re-occur (the other details will be pulled from the schedule item).  Note that there will be a daily build process that will convert the template items into schedule items.

How would you all design this?  And how would you link the binding sources?

Instead of exposing the TemplateID in the ScheduleItem class, I have exposed a TemplateItem property that either returns the corresponding TemplateItem object or returns a new, blank TemplateItem object.  The TemplateItem is only saved to the database if it is marked as recurring (otherwise it is just taking up unnecessary space).  This is working, but I'm wondering if I've done it the best way.  I am not marking the TemplateItem as a child, so to get the data binding to work, I had to explicity call BeginEdit() on the TemplateItem (right after the BeginEdit() call on the ScheduleItem), and during the save process of the ScheduleItem I'm saving the TemplateItem directly (which is actually done before saving the ScheduleItem since the TemplateItem might not exist).

I know I could make the TemplateItem class switchable, but I know that usually points to bad designg.  So I'm wondering if I need to create a new class to handle the specific instances where the TemplateItem is a child to the ScheduleItem (and basically duplicate all of the code with the addition of MarkAsChild()), go down the path of making it a switchable class, or leave it as is?  I have attached a screenshot of the form.  The top half is the ScheduleItem and the bottom half is the associated TemplateItem (if one exists).

Thanks!
Matt

Copyright (c) Marimer LLC