Q:

How can a code in a library project call code in the application project?

In an effort to reduce duplication, I have my app's workspace split into 3 projects:

Main (A library project, where all of the common code lives)
Free (To make the free version)
Paid (To make the paid version)

Behavior in the free version and the paid version must differ sometimes.  How can I "call into" the final projects from the library project?
Here is some sample psuedo-code to illustrate my question:
In the Main project:
private void makeADecision() {
    if (AppCode.isPaid()) {
        // do one thing
    } else {
        // do something else
    }
}

In the Free project:
public class AppCode {
    public static bool isPaid() {
        return false;
    }
}

In the Paid project:
public class AppCode {
    public static bool isPaid() {
        return true;
    }
}

That is basically what I have tried, but it won't compile because the Main project doesn't know about the AppCode class.
Bear in mind that this is only an example, so try not to focus on how an app can tell if it is the paid version or not. :) So far the best solution I have found is to put a string in the resources of all three projects and then make a decision based on its value but I don't like that method. Besides being ugly, I would prefer to keep functionality where it belongs.  That way I can prevent "paid-only" functionality from being compiled into the free version at all and I can avoid having to include any "free-only" code in the paid version.

A:

Step #1: Define an interface in the library, so it is available to all three parties, whose methods are whatever operations you want the library to perform on the app
Step #2: Have the app supply an implementation of the interface to the library via some library-supplied API
Step #3: Have the library call methods on the supplied interface as needed

