Object Factory clarification and design decision

Object Factory clarification and design decision

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


Cosmin posted on Friday, October 17, 2008

Hi guys,

I have read nermin's great post about how to use the ObjectFactory and make it testable as well, but I still have some questions. I may be missing the big picture.
Let's consider the diagram attached. I have a simple class hierarchy that has 2 root business objects Account and Document. Accounts and Documents can be of multiple types(leaves in the objects' tree, CustomerAccount and SupplierAccount, and Purchase/SalesOrder and Invoice respectively).

I've also got a Factory loader that parses the factoryobject attribute and returns the factory. I have one factory for each object type.
I don't really know how to glue things toghether now.

How do I create/fetch/update objects? Is it the same as in classic CSLA? (DataPortal.Create()/Fetch()...).
When I do this:
CustomerAccount ca = CustomerAccount.NewCustomerAccount()

I need the AccountFactory to kick in somehow and create an account of type CustomerAccount at runtime and call it's constructor passing as parameter the coresponding dataobject with the default values(or the CustomerAccountDTO in fetch case). The CustomerAccount constructor will call the parent constructor and pass the DTO so the whole tree is initialized.

How should the code in the NewCustomerAccount method look like and how the code in the AccountFactory.Create() method should look like?

The flexibility I need is that I should be able to add say a new account in the tree, decorate it with the factoryobject attribute and that should be all.

Any input and maybe different ideas will be greatly appreciated. A sample on this would clarify things better. A sample using inheritance in the business layer. Once I get my head around this I'll provide a sample based on the attached diagram.

rkelley replied on Sunday, October 19, 2008

Cosmin,

I am going to attempt to give you some more enlightenment here, hopefully. I have a fully working version of ProjectTracker using the ObjecFactory attribute as well as some other Altdotnet goodness. It is still a little rough right now but it works, I have made the code available to everybody here: http://cslaptrackerfactory.google.code.com 

Now onto your questions:

I've also got a Factory loader that parses the factoryobject attribute and returns the factory. I have one factory for each object type.
I don't really know how to glue things toghether now.

When you say you have a factory for each objec type what do you mean? You have an account factory and a document factory? In my sample I have a factory for each abstract business object type, BusinessBase, BusinessListBase, etc...


How do I create/fetch/update objects? Is it the same as in classic CSLA? (DataPortal.Create()/Fetch()...).
When I do this:
CustomerAccount ca = CustomerAccount.NewCustomerAccount()

Yes, Your methods will still be static on your business objects and NewCustomerAccount() will still do: return DataPortal.Create<CustomerAccount();  The Csla data portal takes care of loading the factory and calling the methods on it.

I need the AccountFactory to kick in somehow and create an account of type CustomerAccount at runtime and call it's constructor passing as parameter the coresponding dataobject with the default values(or the CustomerAccountDTO in fetch case). The CustomerAccount constructor will call the parent constructor and pass the DTO so the whole tree is initialized.

Don't know if my sample will help you out much on this, I did not set up my sample to use DTO's, could be done though I am sure.


How should the code in the NewCustomerAccount method look like and how the code in the AccountFactory.Create() method should look like? 

See Previous

I am not sure that you will be able to achieve the flexibility that you desire for sure. Inheritance can cause some strange issues with this stuff.

Cosmin replied on Monday, October 20, 2008


The link doesn't work.

cslaptrackerfactory.google.code.com could not be found. Please check the name and try again.

rkelley replied on Monday, October 20, 2008

woops: http://cslaptrackerfactory.googlecode.com

 

nermin replied on Monday, October 20, 2008

The format for google code site should be:

http://code.google.com/cslaptrackerfactory

 

However that project does not seem to exist

From: Cosmin [mailto:cslanet@lhotka.net]
Sent: Monday, October 20, 2008 7:12 AM
To: Nermin Dibek
Subject: Re: [CSLA .NET] Object Factory clarification and design decision

 


The link doesn't work.

cslaptrackerfactory.google.code.com could not be found. Please check the name and try again.


rkelley replied on Monday, October 20, 2008

The link i posted redirects to here:

http://code.google.com/p/cslaptrackerfactory/

I guess 6 of 1 half a dozen of the other...

nermin:

The format for google code site should be:

http://code.google.com/cslaptrackerfactory

 

However that project does not seem to exist

From: Cosmin [mailto:cslanet@lhotka.net]
Sent: Monday, October 20, 2008 7:12 AM
To: Nermin Dibek
Subject: Re: [CSLA .NET] Object Factory clarification and design decision

 


The link doesn't work.

cslaptrackerfactory.google.code.com could not be found. Please check the name and try again.


Kevin Fairclough replied on Tuesday, October 21, 2008

With this, is it possible to not send the NHibernate.dll to the client when using remote data portal?

rkelley replied on Tuesday, October 21, 2008

Probably not the way I am doing it for several reasons:

1. I don't use DTO objects, this may change at some point becuase these would be good serializable small objects that would go across the wire really fast.

2. I am doing all of my work inside a UnitOfWork container which is tied to NHibernate fairly tightly. Now granted, the only place that knows about UnitOfWork is the 5 Object Factories,

That's all I can think of right now, somebody else may have some more. It seems like to really make that work you would have to have two seperate "Systems" that passed information back and forth but the one on the other end did the NHibernate work so the primary UI project/installation had no idea. Something like a ServiceBus :  http://code.google.com/p/masstransit/

my .02

Kevin Fairclough replied on Wednesday, October 22, 2008

Another Q if you don't mind "sorry for off topic",  When NHibernate sets the property value on a Load operation doesn't it fire the SetProperty method in the BO? which will fire validation.  I always assumed I couldn't use the managed field directly because of this.

rkelley replied on Wednesday, October 22, 2008

Yes it does fire the set property method, but in the factory I MarkOld the object after the load/update operation is complete so edit levels and the likes do not get messed up.

Copyright (c) Marimer LLC