I've been researching for a solution to this issue on both the new and old forums but have not come to a solution to this or a similar situation, if someone has please point me in the right direction. This situation is as follows:
I have an editable root BO composed of a couple of standard private fields (int's, strings, etc.). Two or more of it's private fields are child BO's of the same type:
public class Driver
inherits BusinessBase
private mDriverName as string
private mDriverNumber as integer
private mDriverPrivateAddressZip as ZipCode 'ZipCode is a child BO
private mDriverWorkAddressZip as ZipCode
.....
end class
public class ZipCode
inherits BusinessBase
private mZipName as string
private mZipCity as City 'City is a also child BO
.....
end class
I'm trying to fetch the driver's record and the zip and city date from the DB in a single shot and call GetZipCodeChild(dr) passing the data reader I got with the driver's details as well as it's childs data. The problem is that I'm getting two childs of the same type on the same datareader and cannot pass one of the childs a datareader as expected by it.
We worked-around the problem by fetching the child's data on separate recordsets from the stored proc and do a dr.nextresult to get to their corresponding data before calling each child's fetch method; but that only works for a single driver and not when we try to get a collection of drivers using a single select statement. For that we resorted to fetching the drivers and feeding the results directly to a grid, but I'd like a more OO approach.
We've verified that we in fact need the zip code class data for both childs, i.e. our use cases do dictate that we have both zip codes on the driver. Do we need to revise our use cases and/or our design of the driver or zipcode classes? The application we are building is very dependant on places (i.e. zip codes, cities, counties, states, etc.), they're not just strings in our problem domain.
Any ideas?
Regards,
Mario Estrella
A possible consideration is to change your GetZipCodeChild() method to take the two properties passed by the dataportal_Fetch of the buisness class. This is what I do with a generic Address class which handles the business logic and structure. The actual persistance is handled by the parent business class in this case. Thus you could define your shared method call as follows:
Public Shared Function GetZipCodeChild(zipName as string, zipCity as string) as ZipCode
return New ZipCode(zipName, zipCity)
end Function
Private Sub New(zipName as string, zipCity as string)
mybase.New()
mZipName=zipName
mZipCity=zipCity
MarkOld()
End Sub
Naturally, placing the object value initialization in the overloaded constructor could be moved up the chain to the shared function, but placing it in the constructor seems more inline with other similar implementations I've seen.
Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
Ahh!! .... Right !!!! ....
Thanks Jim
Copyright (c) Marimer LLC