OO Advice needed

OO Advice needed

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


david.wendelken posted on Wednesday, July 12, 2006

I'm looking for advice on best practices here...

Data Tables:

Measurement
===========
measureId      number
measureText  varchar(50)
statusId          number

Status
======
statusId           number
statusText       varchar(50)

Here are the two classes I need to define:

Measurement : BusinessBase<Measurement>
MeasurementInfo : ReadOnlyBase<MeasurementInfo>

Given that statusId is a meaningless computer-generated Id, it's pretty worthless as a value in a list of measurements (from a human understanding perspective).  So my query (and thus the associated read only properties for MeasurementInfo would be:

select
 m.measureId
,m.measureText
,m.statusId
,s.statusText
from Measurement as M
inner join Status as s on m.statusId = s.statusId

But what about the Measurement object?

Should I have a read-only property StatusText and a read-write property StatusId, where setting StatusId causes the StatusText property to be changed (after a quick query to the database)?

What have people found to be the cleanest and most productive course of action in this situation?

Should I include StatusText as a read-only property of Measurement?  I'm sure to need it when a person takes a look at a detailed Measurement data entry/data review screen...





 

RockfordLhotka replied on Wednesday, July 12, 2006

You might consider using a NameValueList named StatusOptions or something. Then Measurement can expose a read-write StatusId property and a read-only StatusText property - but your UI could use a combobox bound to StatusId and to the StatusOptions object - thus hiding the Id from the user while providing edit capabilities.

Measurement.StatusText is probably best implemented using StatusOptions too - as you'd want it to change as the StatusId changes:

public string StatusText
{
  get {
    return StatusOptions.GetOptions().Value(_statusId);
  }
}

As long as you implement StatusOptions along the lines of RoleList from Chapter 8 (so it is cached) this is typically a good answer.

ajj3085 replied on Wednesday, July 12, 2006

What I do is have a NameValueList for the Status.

Status is then a text property on Measurement.  Setting the string actually looks up the value in the NVL to get the id, and the id is what is actually stored.  The property get is similar, except that it gets the value for the key. 

If the value isn't found when the property is set, I set the statusId = -1; in the getter, I return a blank string if the id is -1.   Also, there's a business rule that says the object can't have a statusId of -1.

HTH
Andy

Copyright (c) Marimer LLC