Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

business rules

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hireprabhu@gmail.com - 17 Mar 2008 12:31 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.