Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dependency Injection ... What is it?
Message
 
To
02/02/2009 13:36:16
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
01378811
Message ID:
01378825
Views:
14
>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 had a post on my blog a while back about this (hmm...the C# code spacing is funky for some reason); I'll have to fix that) :

http://www.rcs-solutions.com/blog/2008/07/12/WhatIsDependencyInjection.aspx

>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.

Your question isn't quite a dependency injection scenario. In your case it's all part of the same class so it doesn't make a huge deal which way you do it. And it's not a dependency, it's a parameter. A dependency is usually something like another class. For example, you have a class which, when an exception is thrown, calls another class that logs the error. Instead of having your class create an instance of the error logging class, you allow the person creating your class to pass in this error logging class instead. It's OK to set defaults if this doesn't happen, though.

In your case, it's probably even a better idea to extract out this code into it's own business object, then have the form call this class to do the calculation. That lets you do things like reuse this code on other forms, via the web, etc.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform