Newbie, explanation on BusinessBase

Newbie, explanation on BusinessBase

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


edika2000 posted on Thursday, December 07, 2006

Hi all,

I'm starting now to use the CSLA Framework, and after reading the book I still have a doubt on how to create a class to be used in differents Business classes.
Example:
I have made a class 'Address' that define a standard address object. The class use the CSLA namespace. The Address class is used by some BusinessBase classes like Man, Woman etc.
The question is: the class Address must inherit from businessbase or can be a normal class? In the case could be a normal class must also be Serializable for proper work with CSLA? Otherwise if must inherit from Businessbase how can I make different Dataportal_Insert and Dataportal_Update when is used by each different BusinessBase classes (the tables for the classes Woman and Man on the database are different)?.

Thanks

Edika

dshafer replied on Thursday, December 07, 2006

I'm certainly no expert in using CSLA, but I think I can answer a few of your questions.  First off, in my opinion, it would be a bad idea to make your address class a non-CSLA class.  There are many reasons for this, but the main reason is that if there is even the slightest chance that your application will be used in any context besides the local one, it will be much more difficult to do so using the dataportal that is built into CSLA.  In other words, if you plan on physically separating the layers of your application you will have to manually provide this functionality for your address class.  If you do choose to create the address class as a non-CSLA class, marking it as Serializable would be one of the tasks that you'd have to perform to make it useful in a physically n-tiered architecture.  The Dataportal_Insert and Dataportal_Update on the address object should not depend on which business object is "using" the address class.  By your comment "the tables for the classes woman and man on the database are different" it almost sounds like you are storing that address information inside the man and woman tables.  If this is the case, you need to look into normalizing the database so that the address information is stored in a separate table.  That way the data access functions in the address class do not need to know anything about the "man" and "woman" tables.  For more information on how to implement your business object classes, you should either read the respective chapters in Rocky's book or check out http://www.onelittlevictory.com/ for some examples.

Brian Criswell replied on Thursday, December 07, 2006

A couple things here.  For starters, strongly consider using a CSLA base class whenever your class:
So for the time being err on the side of using a CSLA base class.

I am puzzled by your last question.  Your Address object only deals with Address data presumably.  And if the Address is a child object of Man or Woman, the DataPortal_XYZ methods will not be called on it because the DataPortal only calls a DataPortal_XYZ method on the root object in an object graph.  You are then responsible for having the root object call Insert or Update or Delete methods that you add to the child objects.

edika2000 replied on Monday, December 11, 2006

Thanks dshafer and Brian,

you've both answer my question, and clear my doubt. I know that the right way for Address object to work is that have an own table on the databse to store his data, but the refactoring of the database is not possible for know. My doubt was about the use of a generic class (really a structure) that is used by many classes just for his generic meaning. I've opted for make it inherit form business base to have the advantage of the validation and authorization rules, but all the Data Access is made by his parent object so the proper table on database is used.
Thanks for now.

Edika

Copyright (c) Marimer LLC