Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Generics, business objects, business rules [solution]
Message
From
01/05/2008 04:14:55
 
 
To
All
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
Generics, business objects, business rules [solution]
Miscellaneous
Thread ID:
01314400
Message ID:
01314400
Views:
52
[problem solved, if you want to take a look]

Please bear with me, I'm not sure if I can communicate this clearly:

I have a system with a number of slightly different Order types, in three different tables, call them OrderType1, OrderType2, OrderType3.

I have common methods in the ABusinessObject to handle various data access used by common validation patterns.

What I want to do is create common Business Rules in ABusinessRule, but I'm not sure how to call a method defined IN the ABusinessObject.cs file.

For example:
public class ABusinessRule : mmBusinessRule
{ ...
   #region validate specific data type methods

   // fake code, doesn't work
   public string ValidateDuplicateOrder<BusinessType>(
      BusinessType oBusiness, 
      string order, 
      string sku) 
         where BusinessType : ABusinessObject 
         // needs a type ... ABusinessObject<EntityType> ... OrderType1 ...
   {      
      // make data access call common to all business object types
      // deriving from ABusinessObject 
      int recsFound = oBusiness.GetDuplicateOrder(order, sku);
      
      if (recsFound > 0)
         AddErrorProviderWarning(...)
   }   
[solution]
After looking at patterns in mmBusinessObjectGeneric<EntityType> I realized that the variable, the generic to follow was <EntityType>, duh.
public class ABusinessRule : mmBusinessRule
{ ...
   #region validate specific data type methods
   
   public string ValidateDuplicateOrder<EntityType>(
      ABusiness<EntityType> oBusiness, 
      string order, 
      string sku) 
         where EntityType : mmBusinessEntity, new()
         // the right type
         // but, what does "new()" do, or mean?
   {      
      int recsFound = oBusiness.GetDuplicateOrder(order, sku);
      
      if (recsFound > 0)
         AddErrorProviderWarning(...)
   }   
So, in a Order Type Business Rule:
public partial class OrderType1Rules : ABusinessRule
{ ...
   public string ValidateDuplicateOrderType1(
      string order, 
      string sku) 
   {
      // note the casting of the business rule's HostObject to a compatible type
      return ValidateDuplicateOrder((OrderType1)this.HostObject, order, sku);
   }
If there's a better pattern, please let me know.
Thanks!
Next
Reply
Map
View

Click here to load this message in the networking platform