public
class Document : BusinessBase<Document>public
class Documents : BusinessListBase<Documents, Document>I am working through some of this same issue. I've stripped polymorphic behavior out of my classes for now and hope to revisit the subject at some point.
One problem that I ran into was the implementation of the collection class for polymorphic child objects - outlined here in Rocky's article that you mentioned:
http://www.lhotka.net/Articles.aspx?id=b8515cd9-7f8e-43df-9efd-cd958dfdc21a
Recently, after trying to work through this, I ran into a problem with implementing the data access methods as talked about in his article, outlined here (last post in the thread):
http://forums.lhotka.net/forums/thread/1285.aspx
Having shelved my pursuit of this for the moment, one avenue I have been giving real consideration to and have done a really cursory glance at is to bypass BusinessBase<T> and inherit right from Core.BusinessBase if I really really want inheritance with polymorphism. There is really not a lot in BusinessBase<T> that would have to be implemented, and it seems that BusinessListBase<T,C> works with C where C is IEditableBusinessObject, which is implemented by Core.BusinessBase.
In my case, there are "Contacts" in the system - some of which are Individuals and some of which are Organizations. Using BusinessBase<T>, my Contact abstract class (which has a good deal of common implementation) needs to be generic <T> simply to pass along the type to BusinessBase<T>. Otherwise it really doesn't serve much purpose. Bypassing BusinessBase<T> allows Contact to be a non-generic abstract class. I haven't really looked deeply into the ramifications and I don't really like breaking away from BusinessBase<T> as staying true to the framework is certainly important.
Of course, using BusinessBase<T> I end up with Contact<Individual> and Contact<Organization>, which are simply not the same class. They may indeed implement IContact, but as mentioned above I ran into some problems trying to implement Rocky's solution in his article and I decided to shelve it until I got some more "real work" done.
skagen00:
Having shelved my pursuit of this for the moment, one avenue I have been giving real consideration to and have done a really cursory glance at is to bypass BusinessBase<T> and inherit right from Core.BusinessBase if I really really want inheritance with polymorphism. There is really not a lot in BusinessBase<T> that would have to be implemented, and it seems that BusinessListBase<T,C> works with C where C is IEditableBusinessObject, which is implemented by Core.BusinessBase.
This is, in fact, the only reason Core.BusinessBase still exists. During the book review process it was suggested that Core.BusinessBase could go away - which is absolutely true. But I kept it specifically because you can create a NON-GENERIC version of BusinessBase by inheriting from Core.BusinessBase.
I would NOT have your business objects inherit directly from Core.BusinessBase - that is not a design for which Core.BusinessBase is intended. However, what you can do is create your own BusinessBase that inherits from Core.BusinessBase and then have your business objects inherit from that new base class.
This new BusinessBase class should (at a minimum) implement a Save() method - obviously returning type Object rather than a strong type, and GetIdValue(). You may also want to implement the protected DataPortal_XYZ methods.
I originally had just such a class in the framework, but dropped it in favor of only supporting BusinessBase<T>. I still think that was the right choice, because it reduced my surface area for testing and for the book (as it would have taken pages to explain the non-generic version, and then to show how to use it within ProjectTracker, etc.) Still, in anticipation that someone would want to avoid all the complexity of generics, I did keep Core.BusinessBase so you could easily create a non-generic BusinessBase if that was useful.
All that said, in most cases you should be able to use IEditableBusinessObject to achieve polymorphic results without giving up the benefits of BusinessBase<T>.
From: tpancoast [mailto:cslanet@lhotka.net]
Sent: Friday, July 07, 2006 5:35 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Density Correction (or Generic Polymorphism Whaaaa?)O.K. I am still reading some of the older messages in the forums, but this message confuses me again. My understanding is that you can create a non-generic (concrete) version of BusinessBase simply by inheriting from BusinessBase and specifying its type parameter without specifying any new type parameters for the new class. There shouldn't be any need to go back to Core.BusinessBase. For example, this creates a new non-generic (concrete) class.
RockfordLhotka:
skagen00:
Having shelved my pursuit of this for the moment, one avenue I have been giving real consideration to and have done a really cursory glance at is to bypass BusinessBase<T> and inherit right from Core.BusinessBase if I really really want inheritance with polymorphism. There is really not a lot in BusinessBase<T> that would have to be implemented, and it seems that BusinessListBase<T,C> works with C where C is IEditableBusinessObject, which is implemented by Core.BusinessBase.
This is, in fact, the only reason Core.BusinessBase still exists. During the book review process it was suggested that Core.BusinessBase could go away - which is absolutely true. But I kept it specifically because you can create a NON-GENERIC version of BusinessBase by inheriting from Core.BusinessBase.
I wonder why read-only objects didn't take this approach? I notice that the only reason (unless I'm missing something) ReadOnlyBase is generic is to strongly type the Clone method for the ICloneable interface. I wonder in some ways if there is a point at which it's good not to introduce generics.
Correction: I missed that Equals also is implemented with T considered.
ajj3085:
Well, one problem is that any class derived from Document would return Document from the Save method, not my MySubClassedDocument, which is what you'd expect. There are other problems as well, if you search this forum you'll come across threads detailing them more.
Copyright (c) Marimer LLC