Inheritance

Inheritance

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


lprada posted on Tuesday, July 04, 2006

   Hi, I need help with inheritance and CSLA.NET.

I have 2 classes, Person and Employee How do I create them?

 

[Serializable()]

class Person : BusinessBase<Person>{

private string lastName;

}

 

[Serializable()]

class Employee : Person{

private SmartDate startWorking;

}

I have no idea what to do?

ajj3085 replied on Wednesday, July 05, 2006

Generics and inhertitance have a hard time mixing.. but here's what you could do..

class Person<T> : BusinessBase<T> where T : Person<T> { }

class Employee : Person<Employee> { }

I believe that should work... but you'll still likely have problems working with the base class (where you can't care what kind of person you are working with).

HTH
Andy

lprada replied on Thursday, July 06, 2006

To try to understand , if I have the following classes: Animal, Mamal, Dog. How do I create Them?

RockfordLhotka replied on Friday, July 07, 2006

The first, and most important, thing to remember about inheritance is that it should only be used to gain BEHAVIOR, not DATA.

The Animal, Mammal, Dog example, and similar examples, are really terrible. They are used in introductory object-orientation classes to teach the basic idea of inheritance, but they have no use in the real world - and in fact are very destructive examples.

Why? Because they focus on inheriting attributes (data) rather than behaviors.

The real question SHOULD be, what behaviors are at the Animal level? What do all animals have in common in terms of behavior? Probably just that they have a start and end to their life. All animals are mortal.

Then, what are all the behaviors in common across all Mammals? This would include the concept of being born, and consuming mother's milk, and growing fur/hair. These are the unique behaviors of a mammal.

Now there is no doubt that you need some extra attributes/data to implement the behaviors of Mammal - but it is all about the behavior, not about the data!! And this distinction is almost never made when using these flimsy examples for inheritance.

And what's even worse is that these examples totally ignore the key concept of a use case (or story). What is the purpose/mission/responsibility of your Dog class? What is the user trying to do with it? Is it merely responsible for allowing the user to enter valid data about a dog? Or is it part of a business process that is simulating the life of a dog? Or is it a read-only object designed to display data about a dog? The point is, these examples never come with any business domain context - so there's no way to design or implement them, because no one knows that they are suppose to actually do!

I know this isn't the answer you were looking for, and I don't mean to put you off from OO design. But you need to realize that your question can't be answered in any meaningful way - at least within the context of CSLA .NET - because CSLA .NET is designed to enable behavioral objects.

I think someone already provided the trivial answer:

Public MustInherit Class Animal(Of T As Animal)
  Inherits Csla.BusinessBase(Of T)

Public MustInherit Class Mammal(Of T As Mammal)
  Inherits Animal(Of T)

Public Class Dog
  Inherits Mammal(Of Dog)

But again, this is pretty meaningless, as it doesn't convey meaning within a use case and may not be at all what is needed to solve the business problem.

lprada replied on Sunday, July 09, 2006

thank you rocky, may be a more value example was my real need Person, Employee and RuralEmployee but i try to get a answer in a more general way, because I didn't understand how to do inheritance with your framework. Now I do. Thank you again, and I am very sorry about my English, I am form Argentina and I speak Spanish.

 

 

Copyright (c) Marimer LLC