As I am looking to subclass the CSLA framework, I have the concept down, but I have never actually done it. Does anyone know of a place that I could go to in order to help point out the pitfalls and standard way of doing things?
Thanks
Hey Tim,
I just finished doing this against the 2.0.3 version. Was pretty easy, but I did get a little confused with the generics business. I can send to you if you'd like, or we can compare.
Regards,
Mike
Generics is what is messing me up too. Can you reply to this and attach a zipped copy of just BusinessBase<T>? I want to figure it out as much as I can so it sticks.
Thanks a ton.
Apologies Tim, I missed your post last night.
Keep in mind I'm not really sure what I'm doing either, any comments appreciated. I'm sure you'll want to change the namespace and class name.
using
System;using
System.Collections.Generic;using
System.Text;using
Csla;namespace
Buoy.BusinessObjects203{
[
Serializable()] public abstract class BuoyBusinessBase<T> : BusinessBase<T> where T : BuoyBusinessBase<T>{
// We may want to mark a new object as clean, so that way // it won't get saved if the user hasn't modified any // properties. public virtual void MarkAsClean(){
this.MarkClean();}
}
}
Hey Andy,
Thanks, just the type of comments I'm looking for.
The reason I want to mark a new object as clean came from this thread http://forums.lhotka.net/forums/thread/2477.aspx
Basically, I don't want to prompt the user with "Do you want to save changes" if it's a new object and the user hasn't modified anything. In that case the object should not be saved at all.
I'm not sure if this should be done by the bo itself or the UI, as it seems like it's a UI function, but I'm not sure.
Thanks,
Mike
Ok, I am confused.
public abstract class BuoyBusinessBase<T> : BusinessBase<T> where T : BuoyBusinessBase<T>
I thought this says BuoyBusinessBase<T> inherits from BusinessBase<T> Where T is type BuoyBusinessBase<T>?
If that is true, it seems like a circular reference.
Tim,
I'm no expert in generics, honestly I'm not really sure how that works - maybe someone can explain?
When I tried to subclass the CSLA classes, it took me a while to even compile it :) - I could very well be doing something wrong.
But, if you look at BusinessBase<T>, it's just about the same:
public
abstract class BusinessBase<T> : BusinessBase where T : Csla.BusinessBase<T>I'd love to get a good explanation on this.
Mike
What I have read so far is that when you inherit from a generic class, you have to repeat any constraints. So If you are inheriting from:
[
Serializable()]The constraint here is where T : BusinessBase<T>
So when I inherit from it, I need to do the following
[
Serializable()]So that explains how to do it, but I still want to know what the
where T : BusinessBase<T>
in the first declaration means.
RockfordLhotka:The intent of the constraint is to force a subclass to pass itself as T - to force T to inherit from MyNewBase.
I think I can see how that would only sound more confusing.
You could interpret what you said as simply "to force a subclass of MyNewBase to inherit from MyNewBase." Sounds kinds of silly expressed that way, and that would lead to confusion because we know this really isn't silliness.
If I'm understanding this correctly (and I am NO generics expert) I think the two significant points are:
It means that T needs to be a decendent of BusinessBase<T>.
Thus I couldn't do this:
public class Individual : BusinessBase<string>
The VB version of a company level Base class looks like this:
===================================================
<Serializable()> _
Public MustInherit Class MyBusinessBase(Of T As MyBusinessBase(Of T)) Inherits BusinessBase(Of T)===================================================
Then a regular Root Bo would look like this:
<Serializable()> _
Public Class Acct Inherits MyBusinessBase(Of Acct)===================================================
Thanks you two. :)
Ok I think I got generic inheritance down. I have a new question.
Do I need to override all non-public members of BusinessBase<T>? This way I expose them at the level that I will actually be using them?
That would kind of defeat the purpose of inheritance, wouldn't it? ;)
I'm not sure what you mean by your question, perhaps you could rephrase it?
Yea, I thought about it after I typed it. It didn't make sense.
I guess what I am asking, is after I abstract BusinessBase<T> to my class,
public abstract class ANBOBusinessBase<T> : Csla.BusinessBase<T> where T : ANBOBusinessBase<T>
is there any code in it that I need to bring up to my class level to expose it? There is some custom stuff I want to do but if there wasn't and my only objective was to abstract the CSLA framework into my own namespace and thus allow my code to be upgraded with future versions of the CSLA framework, then my subclass could basically consist of
[
Serializable()]Is that right?
That's pretty much it, yep!
is there any code in it that I need to bring up to my class level to expose it? There is some custom stuff I want to do but if there wasn't and my only objective was to abstract the CSLA framework into my own namespace and thus allow my code to be upgraded with future versions of the CSLA framework, then my subclass could basically consist of
[
Serializable()]
public abstract class ANBOBusinessBase<T> : Csla.BusinessBase<T> where T : ANBOBusinessBase<T>
{ }Is that right?
I saw in another post where Rocky said that you should only subclass the following classes.
BusinessBase<T>
BusinessListBase<T,C>
CommandBase
ReadOnlyBase<T>
ReadOnlyListBase<T,C>
NameValueListBase<K,V>
What about
EditableRootListBase
<T>
DeHaynes:What about
EditableRootListBase<T>
SortedBindingList<T>
SmartDate
FilteredBindingList<T>
Copyright (c) Marimer LLC