Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dependency Injection ... What is it?
Message
De
02/02/2009 14:03:46
 
 
À
02/02/2009 13:36:16
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
01378811
Message ID:
01378816
Vues:
15
>As I've studied OOP a little more recently, I hear of this matter of depency injection. Can someone help explain this to me, from a VFP perspective.
>
>I think my question here may be associated to it... On my form class, I have a method that will calculate the total amount of the invoice, by summing the line item costs based on the parent key.
>
>So, I have a method on the form called CalculateLineItemCost().
>
>Now, I could architect this thing where the method assumes the current parent key from a form property which is (kept updated by the navigation of the form), or I could architect it to where the parent key value has to be passed into the method by the calling method.
>
>pseudo code of each example to follow:
>
>Assume parent key from a form property:
>
>Method CalculateLineItemCost()
>
> liParentKey=thisform.iParentKey
> select sum(qty*cost) from LineItems where ifkey=liParentKey into array laTotalValue
> return laTotalValue
>
>EndMethod
>
>
>
>or, I could require the parent key value to be passed in, like this:
>
>Method CalculateLineItemCost()
>lparameters tiParentKey
>
> select sum(qty*cost) from LineItems where ifkey=tiParentKey into array laTotalValue
> return laTotalValue
>
>EndMethod
>
>
>So, which way is considered the best practice?

Well the first option relies on 'thisform' being resolvable so .......
Why not lump them together using the second option but:
If there's a parameter then use it.
If there's not then look for ThisForm.
If that's not there then throw an exception.....
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform