Hi,
Can somebody let me know what is the best way to implement the
business rules. I am quite new to C# & oops
Class A {
Function Busrules { base class rules must run}
}
Class B: A {
Function Busrules { Having its own rules.}
}
When I create object of class B and call Busrules it should first run
the base class rules and then the class B rules..
How to implement this..
Thanks
Jon Skeet [C# MVP] - 17 Mar 2008 12:36 GMT
> Can somebody let me know what is the best way to implement the
> business rules. I am quite new to C# & oops
[quoted text clipped - 11 lines]
>
> How to implement this..
I suspect you mean a call like this:
base.BusRules()
within B.BusRules.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Bill Butler - 17 Mar 2008 13:08 GMT
> Hi,
> Can somebody let me know what is the best way to implement the
[quoted text clipped - 12 lines]
>
> How to implement this..
Jon has already answered your question, but I have one for you.
Are you sure that using inheritance is the best way to go with this?
I am trying to envision why a business rule might legitimately be a
candidate for subclassing from another business rule. I can think of
reasons why different business rules might share some implementation
details, but that can be handled via composition in a far cleaner
manner.
Would you be able to provide a simplified sample of when this makes
sense?
My concern is that you could run in to trouble if you are attempting to
do something like
Class A --> does X
Class B --> does X and Y
So I subclass A to share the X behavior
Next I need a class that does Y and Z, but not X
What do I do now?
I have already tied my Y logic to the X logic.
Anyway...be fore I go on any further, perhaps you can demonstrate your
usage.
Possibly, it make sense in your business.
Bill
Raj - 20 Mar 2008 04:49 GMT
Thanks bill for the information.
The requirement is quite simple....
We need to develop a class, which has its own impementation.
Whoever inherit the base class, they should implement the member
function called business rules. I dont want to use abstract functions
as it doesn't have any impementation [There are some implementation
which should be implemented by those who inherit the base]. How do i
do that ?.
Class A{
Void businessrules { Some core implementation}
}
Class B: A
{
Businessrules {
Need to execute the business rules of Base first [Developer
should not have option to avoid this]
Other impementation.
}
Raj - 20 Mar 2008 05:00 GMT
Yes bill, I need to do something like
Class A --> does X
Class B --> does X and Y
Steve Gerrard - 20 Mar 2008 08:12 GMT
> Yes bill, I need to do something like
> Class A --> does X
> Class B --> does X and Y
I would do it something like this, where BusRules itself is not overrideable,
but an extra method is, which is called by BusRules:
public class A
{
public void BusRules()
{
BaseRules();
ExtraRules();
}
private void BaseRules()
{
// these are always done
}
protected virtual void ExtraRules()
{
// empty in base
}
}
public class B : A
{
protected override void ExtraRules()
{
// do more rules here
}
}
sloan - 17 Mar 2008 18:40 GMT
base.Busrules.
You can also look at the "Template" design pattern.
http://www.dofactory.com/Patterns/PatternTemplate.aspx
or something like that.
you can either write abstract methods in the base.
or allow the subclass to override them.
> Hi,
> Can somebody let me know what is the best way to implement the
[quoted text clipped - 14 lines]
>
> Thanks