Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Generics, business objects, business rules [solution]
Message
De
01/05/2008 04:14:55
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
Generics, business objects, business rules [solution]
Divers
Thread ID:
01314400
Message ID:
01314400
Vues:
53
[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!
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform