Inheritance CSLA

Inheritance CSLA

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


juancho559 posted on Sunday, April 06, 2008

Hi Everyone,

I'm new with CSLA.NET and I'm frustrated because I haven't found the way to make the inheritance between entities. I've read in other post that the inheritance in CSLA .NET is centred in the behavior, not in the data, but I really need to have different objects. For example, I have some objects like Person, Employee and Client. This objects share common fields and common behaviors, the only difference between this objects are some fields, like an Employee has an StarDateWorking and the client has some other fields. So, I decided to qualify a Person like a base class, and inheritance Employee and client from person. I wish to know, what's the best way to model this objects in CSLA.NET.

I appreciate your help...

dlambert replied on Monday, April 07, 2008

There's effectively no difference (that I've seen) in handling inheritance when using CSLA vs. not using CSLA. Since all behaviors of an object are found together, however, really deep and complex inheritance will get complex in a hurry.

For example, I've successfully used inheritance to handle a bunch of reference tables that all have a very similar DB structure (mandated by our DBA). This worked well because of the extremely high coincidence of structure and behavior across objects, and because I needed to construct enough of these child objects to make the up-front work pay off.

In your case, you could probably make inheritance work, but would it be cost-effective in terms of development time? How about building an interface for these common objects to represent the common aspects of structure?

juancho559 replied on Monday, April 07, 2008

Hi, thanks for your response,

I don't need an interface because the behavior is common between the objects (Person, Employee, Client). The only diference are the fields. I know that in CSLA the idea is to have inheritance centred in the behavior, but I really need to separate this objects. I have a base class (Person) and two objects(Employee, Client) are inheriting from base class. I just want to know how can i make the inheritance with CSLA?, Where Do I have to put both factory and DataPortal_xyz methods?  

 

 

JTWebMan replied on Monday, April 07, 2008

1. Make the constructor protected instead of private.
2. Make sure all you fetch, insert, update, and delete functions are mark protected and overridable.
3. I normally make all my properties overridable as well.

Now when you inherite from the object you will get all of those methods.You will not get any of the shared/static methods so you will have to write those again to follow the use cases for that object.

Hope that helps.

JT

juancho559 replied on Monday, April 07, 2008

JT, thanks a lot for the response,
Do you have a sample implementing inheritance?

 

 

 

JTWebMan replied on Tuesday, April 08, 2008

Sorry for the delay. Do you want one in C# or VB?

JT

juancho559 replied on Tuesday, April 08, 2008

Could you send me the sample in C#?

Again, thanks a lot...

 

machocr replied on Friday, July 15, 2011

Hi Juancho, has you lucky on this?  has you a sample about this?  I have the same problem and I'm not sure about a proper way to implemnt it to have full benefices of this great framework.  I'd like to casacade the inserts, undates, deletes etc, so I'd like to have a kind of sate on for each level.

I'm not sure if that's a good idea either. 

k2so replied on Thursday, September 18, 2008

In the process of updating my parent class from the 2.0 to the 3.5 style, I notice the managed fields from the parent class are not accessible from the child.
Does this mean enabling to inherit, we have to make the

PropertyInfo blahblahProperty = RegisterProperty(...);

assignment protected as well? Or should we use protected backing so we can have access to the variables from the parent?

Which way is more orthodox in CSLA?

JTWebMan:
1. Make the constructor protected instead of private.
2. Make sure all you fetch, insert, update, and delete functions are mark protected and overridable.
3. I normally make all my properties overridable as well.

Now when you inherite from the object you will get all of those methods.You will not get any of the shared/static methods so you will have to write those again to follow the use cases for that object.

Hope that helps.

JT

ayubu replied on Thursday, September 18, 2008

In order to access the managed field i mark them with protected

Copyright (c) Marimer LLC