Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dependency Injection ... What is it?
Message
From
02/02/2009 13:36:16
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Title:
Dependency Injection ... What is it?
Miscellaneous
Thread ID:
01378811
Message ID:
01378811
Views:
73
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?
Next
Reply
Map
View

Click here to load this message in the networking platform