Factory Method Question?

Factory Method Question?

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


RangerGuy posted on Monday, July 24, 2006

I've been meaning to ask this question for sometime.

I read in the book that we use "Factory Methods" like MyCar.GetNewCar() or MyCar.GetCar(1). So that we can control how our BO's are created and fetched etc. Which I really like, but I notice that in the ReadOnlyInfo Objects we use constructors that accept either values or a datareader.

Is it because the constructor is marked as internal? What if we want to use this Info object as more than a child of a list. What if we want to use it as a light wieght way of displaying the info of a single BO?

Would it be a acceptable design descion to create public factory method as well like

MyCarInfo.GetCarInfo(MyCarGuid);

Tom Cooley replied on Monday, July 24, 2006

Sounds like the behavior you are describing is a ReadOnlySwitchable. The public factory method that accepts a unique id is a root object behavior. Personally, I think this seems like a reasonable design if your application calls for it.

ajj3085 replied on Tuesday, July 25, 2006

Yes, the only reason the constructors may take DataReader is because they are marked internal, and thus the UI never knows about this.  You can do things internally that you wouldn't allow publicly for the sake of efficency.  The values vs. datareader is simply to show you can create internal objects either way.

Personally I NEVER expose constructors, even internally... all objects which are children get created via internal factory methods.  Mainly I do this for consistency.

I think it'd be ok to load a car via guid.  There needs to be some way to load a root object after all.

Andy

OpticTygre replied on Tuesday, July 25, 2006

Isn't that the point of having the GetObject functions in the info classes, like:

 Dim myCar as Car = myCarInfo.GetCar

Tom Cooley replied on Tuesday, July 25, 2006

Yes, when you need to switch from viewing lightweight data to editing object details.

I think RangerGuy's question was whether or not it is acceptable to allow a xxxInfo class that is typically a read only child behave also like a read only root (therefore becoming switchable).

Copyright (c) Marimer LLC