Object Creation - Any Ideas?

Object Creation - Any Ideas?

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


jkellywilkerson posted on Tuesday, September 05, 2006

Greetings:

I have a use case that requires that an object be created using the ID of another object.  On the surface it appears to be a child object, but a child collection is not required.  For instance, I have an NVL object, CarrierNVL, for populating a combobox.  Once a selection is made, including the defaults, general information is displayed from a RO object, CarrierRO.  Based on the selection, the user wants to click "Add New Product..." to add a new product; however, the ID of the Carrier needs to be a field of the Product object.  Does that make the Product object a child?  Does the Carrier ID become the criteria passed to the NewProduct() factory method?

Not sure how the factory method and data portal method should look;

public static Product NewProduct()

{

if (!CanAddObject())

throw new System.Security.SecurityException("User not authorized to add a product");

return DataPortal.Create<Product>();

}

or

public static Product NewProduct(Guid carrierID)

{

if (!CanAddObject())

throw new System.Security.SecurityException("User not authorized to add a product");

return DataPortal.Create<Product>(carrierID);

}

and

[RunLocal()]

private void DataPortal_Create(Criteria criteria)

{

_ProductID = Guid.NewGuid();

_CarrierID  = criteria.ID; //?????

_EnteredBy = Csla.ApplicationContext.User.Identity.Name;

_EntryDate.Date = DateTime.Today;

ValidationRules.CheckRules();

}

or

[RunLocal()]

private void DataPortal_Create(Guid carrierID)

{

_ProductID = Guid.NewGuid();

_CarrierID  = carrierID; //?????

_EnteredBy = Csla.ApplicationContext.User.Identity.Name;

_EntryDate.Date = DateTime.Today;

ValidationRules.CheckRules();

}

Any input is greatly appreciated.

Kelly.

RockfordLhotka replied on Tuesday, September 05, 2006

jkellywilkerson:

Does that make the Product object a child?  Does the Carrier ID become the criteria passed to the NewProduct() factory method?



No, it doesn't make it a child. I would suggest that Carrier ID is a parameter to NewProduct(). Or for better abstraction yet, CarrierRO could be the parameter, so NewProduct() can get whatever fields it needs from that object - it minimizes the amount of knowledge/code required in the UI.

In this model, your call to DataPortal.Create() needs to pass a criteria object to the data portal. That criteria object would contain the Carrier ID value so as to make the value available within DataPortal_Create(). This is exactly the same as calling Fetch(), though you might have a different criteria class for your create operation.

jkellywilkerson replied on Tuesday, September 05, 2006

Thanks Rocky - I'll give that a try.

Kelly.

Copyright (c) Marimer LLC