Could someone PLEASE tell me EXACTLY what is the big deal about Type rules?
I am under the impression that Type rules where added because of some tremendous benefits but I have failed to see such benefit.
Please educate me.
The benefit from using type rules is that each instance of a type doesn't load it's own "copy" of the rules into memory. With type rules only one "copy" of the rules is created and stored in memory. The type rules makes each object more lightweight and faster.
For more info, see Rocky's change log for 2.1 at http://www.lhotka.net/Article.aspx?area=4&id=f12cc951-0452-42d1-96a6-cfa7656863b1
/Henrik
Thanks,
Well, I was poking around the CSLA code when all of the sudden I stumbled upon the BusinessBase constructor and a lot of thing started to make sense, specifically, I noticed that this constructor has the following two lines of code:
if (!Validation.SharedValidationRules.RulesExistFor(this.GetType()))AddBusinessRules();
if (!Security.SharedAuthorizationRules.RulesExistFor(this.GetType()))AddAuthorizationRules();
Now I can understand how type rules can reduce load type and memory overhead.
Well, with my new founded knowledge, I think I am ready to make a fool of myself again and make a suggestion regarding how to make the decisions on whether to use type rules or instance rules more clear cut. This suggestion may be absurd since I am still new to the CSLA but here I go:
I suggest changing the signature of the instance RuleHandler from:
public delegate bool RuleHandler(object target, RuleArgs e);
public delegate bool RuleHandler<T, R>(T target, R e) where R : RuleArgs;
To:
public delegate bool RuleHandler(RuleArgs e);
public delegate bool RuleHandler<R>(R e) where R : RuleArgs;
The reason I am suggesting this change is because if you think about it, you don’t have to have the “target” parameter on instance rules because when you create instance rules you have access to the actual object so what’s the point.
Further more, making this change will make it really clear on when to use type and instance rules because the CSLA would crash if you where to try to push a type handler into and instance rule or vise versa.
Does this make sense to you?
In my opinion, breaking changes are simply a fact of life and there is not much we can do about it.
I think one of the primary aims of the framework should be towards simplicity of use. Having an instance RuleHandler that accepts a “target” parameter for no good reason simply creates complexity.
I think I remember reading a post where Rocky expressed concern regarding the complexity of having two types of rules. I definitely agree that two types of rules adds complexity and I am just proposing a way to make the decision about when to use de different rules much more straight forward.
Anyone else has an opinion regarding this subject? Rocky, what do you think?
rxelizondo:In my opinion, breaking changes are simply a fact of life and there is not much we can do about it.
rxelizondo:I think one of the primary aims of the framework should be towards simplicity of use. Having an instance RuleHandler that accepts a “target” parameter for no good reason simply creates complexity.
rxelizondo:I think I remember reading a post where Rocky expressed concern regarding the complexity of having two types of rules. I definitely agree that two types of rules adds complexity and I am just proposing a way to make the decision about when to use de different rules much more straight forward.
ajj3085 :
Well, I am speaking for the new generations that will be learning and adopting the CSLA framework. The idea is to keep the framework simple, we are already starting to see some awkward code in the CSLA in the name of backwards compatibility that just makes things complex for new user.
Now, lest just supposed that this new change was implemented, how big of a deal would it be to make the changes on our programs?
Since most people would already be using type rules, chances are making this change will not break any code at all for the people following the use only type rules patters.
But what about the people that do use instance rules? Well, all they would have to do is remove the “target” parameter from their functions and all should work just fine, is that really that much of a big deal?
Thanks.
rxelizondo:Well, I am speaking for the new generations that will be learning and adopting the CSLA framework. The idea is to keep the framework simple, we are already starting to see some awkward code in the CSLA in the name of backwards compatibility that just makes things complex for new user.
rxelizondo:Now, lest just supposed that this new change was implemented, how big of a deal would it be to make the changes on our programs?
rxelizondo:Since most people would already be using type rules, chances are making this change will not break any code at all for the people following the use only type rules patters.
rxelizondo:But what about the people that do use instance rules? Well, all they would have to do is remove the “target” parameter from their functions and all should work just fine, is that really that much of a big deal?
xal:
Not sure I follow your example but I think you are referring to the idea of having the ValidationRules object call instance objects outside the object that is hosting it.
If I understand your example correctly, I think you could still do the same thing using a type rule that will then delegate the call to the instance (live) object.
I agree with you that flexibility is nice, as long as there is a point to that flexibility, for me having a “target” parameter on instance rules is akin to someone climbing Mount Everest carrying a bowling ball with them, since they wont find a bowling alley up there, what is the point on having the extra weight.
Thanks.
I for one would oppose strongly against changing the signature, if the breaking change is only for the beauty of our code. I've adopted the breaking changes from 2.0 to 2.1 due to the major memory and performance improvements of type rules.
I've already released 2 apps last week based on v2.1 and I don't want to neither alter the code in these and re-release nor keep a v2.1 and a v2.1.1 side by side just because newcomers needs simplicity. In the end I think having one signature of rules is the simplest anyway.
Cheers
/Henrik
Henrik:
I think is *very* important to make it as easy as possible for newcomer to adopt the framework, after all, they are the ones that will make the CSLA an even bigger success.
There are 3 things to note here:
:I think is *very* important to make it as easy as possible for newcomer to adopt the framework, after all, they are the ones that will make the CSLA an even bigger success.
:These breaking change do not have to require a new release, this change could be added when other braking changes are also required (you know they will happen).
rxelizondo:This is not beauty code changes, in my opinion this are logical changes. Like I said before, there is absolutely no reason why the RuleHandler should require the “target” parameter for instance rules.
rxelizondo:Other than making the code more logical, having different RuleHandler signature will allow the compiler to verify that you are adding static methods to type rules and instance methods to instance rules during compile time and not wait until runtime.
rxelizondo:I agree with you that flexibility is nice, as long as there is a point to that flexibility, for me having a “target” parameter on instance rules is akin to someone climbing Mount Everest carrying a bowling ball with them, since they wont find a bowling alley up there, what is the point on having the extra weight.
Further investigation of the CSLA code revealed that it is possible to add static functions to instance rules. I already knew this but I had forgotten.
Needless to say, if instance rules allow for static methods then the MethodHandler signature must remain the way it is right now, end of discussion.
Copyright (c) Marimer LLC