Business Rules Logic implementation Question

Business Rules Logic implementation Question

Old forum URL: forums.lhotka.net/forums/t/4017.aspx


isharko posted on Monday, December 10, 2007

Hello all,

We are developing highly interactive WinForm app that is used by underwriters to generate quotes.

We have been using CSLA 2.1x to create BOs behind the forms.

We now came to the point where we need to implement the business rules logic that is not dependant on one object but on several of them.

Ex:

We have three objects:

WorkSheet (editable root)

PrevQuoteInfo (readonly)

ConditionsList (editable collection)-> Condition (editable child)

 

We need to implement the following business rule.  

If some property in WorkSheet more than some property in PrevQuoteInfo then

add some condition in ConditionList object and do this only if the Worksheet.State<>"IL"

 

Our goal is to simplify the maintenance of the business rules logic because it is everchanging.

For that reason we would like to 

      1)separate the business logic from the aforementined Business Objects

         and put them into the separate object.

      2)make some rules database driven so we don't have to re-deploy our app 

It is very important to note that the business rules have to be evaluated  in interactive manner and display the results to the user right away (underwriters have to see condition added right after they change some property that would trigger the business rule that adds that condition).

So far all we could think of  is this:

Create a businessrules class that contains the business rules methods than on every property change go and search for the rule appropriate to it and then dynamically run the business rule method that was returned from the search logic.

I tried to find the topics related to this but could not find an answer I am looking for.

Please give me your thoughts on this.

Thank you in advance,

Igor.

  

 

 

Wal972 replied on Monday, December 10, 2007

Hi Igor

You might want to attach the business rules in the form of a validation Below is a thread this discusses (briefly) this.

http://forums.lhotka.net/forums/thread/19467.aspx

Hope that helps

Ellie

isharko replied on Wednesday, December 12, 2007

Ellie,

 

Thank you for your reply but the common rules doesn't solve our problem.

Our business rules are workflow-like not validation-like

There are several objects involved not one.

If obj1.limit > obj2.curlimit then obj3.DoSomething

As far as I understand the common rules are validation-oriented.

Igor.

JoeFallon1 replied on Thursday, December 13, 2007

Igor,

You can create a special Root object which *contains* your other BOs. Because it is a Root object it can have its own rules and methods.

e.g you could override IsValid and call root.MySpecialValidationMethodCode and then check:

If obj1.limit > obj2.curlimit then obj3.DoSomething

I do this all the time and call this type of BO a Use Case Controller object. (I also call it a Unit of Work - but apparently that has a more technical meaning than what I am using it for.)

This root BO can have Validation rules, create, fetch and save methods, etc.

It is responsible for fetching your other 3 BOs and then validating the rules between them and then saving them in the correct sequence.

Joe

amit replied on Friday, December 14, 2007

Hi JoeFallon1,

I am also trying to access multiple objects in one class. as per your logic , I  have to create one root class.and access the three different object in that class.(by adding it's reference or inheriting these class in root class).

Can u please elabroate this.

 

JoeFallon1 replied on Friday, December 14, 2007

Here is a sample outline:

<Serializable()> _
Public Class MyUOW
  Inherits BusinessBase(Of MyUOW)

  Private mBO1 As BO1
  Private mBO2 As BO2

Protected Sub New()
  'require use of factory methods
End Sub

Public Overridable ReadOnly Property BO1 () As BO1
Get
  Return
mBO1
End Get
End
Property

Public Overridable ReadOnly Property BO2 () As BO2
Get
  Return
mBO2
End Get
End
Property

Protected Overrides Sub AddBusinessRules()
   
'add rules here that interact with BO1 and BO2 (plus rules for any other private variables in this class.)
End Sub

Public Shared Function NewMyUOW(ByVal userid As Long) As MyUOW
  Return DataPortal.Create(Of MyUOW)(New CriteriaLongKey(GetType(MyUOW),
"NewMyUOW", userid))
End Function

Protected Overrides Function GetIdValue() As Object
  Return
"MyUOW." & mUserid.ToString
End Function

Protected Overridable Overloads Sub DataPortal_Create(ByVal criteria As Object)
    Dim crit As CriteriaLongKey = DirectCast(criteria, CriteriaLongKey)
    mUserid = crit.Key

   GetData()   'fetch BO1 and BO2 here

  MarkNew()

  ValidationRules.CheckRules()
End Sub

 

Joe

 

isharko replied on Friday, December 14, 2007

Joe,

Thank you for your reply.

I think the implementation your offering is a very good idea.

The only thing would be different for us is that in our scenario the objects are already exist in memory and don't need to be loaded.

The MyUOW would reference and manipulate bo1 and bo2 based on the rules being evaluated.

Igor.

white911 replied on Friday, December 14, 2007

Joe,

I would appreciate if you could give us a full example for the Case Controller object, with fetch, save, delete examples, plue examples where you interact with 2 or more objects.
Also, explain how the data binding works. What is my Binding Source? How do I bind?

Thanks

amit replied on Monday, December 17, 2007

Hi,, JoeFallon1

Thanks for your reply.

Copyright (c) Marimer LLC