views:

39

answers:

1

Hi,

I create an add-on for the product Foo. There are different versions of Foo, namely version 1, 2, 3 and 4.

These versions have a mostly compatible API, but not fully.

I currently have 5 projects:

  • DotNetCommon - here are the common methods which could be used if I create an add-on or something other than the Foo product.
  • FooOne
  • FooTwo
  • FooThree
  • FooFour

The Foo*-projects contains the add-in for version 1-4 of Foo.

There are a lot of duplicated files in the Foo*-projects, as there are a lot of things in the API which are identical for all versions of Foo. It would be nice to separate out everything which is common for all Foo-versions.

Why not just create a common assembly for all versions of Foo called FooCommon?

If I would put all classes which are common for all versions of Foo into a new library project, I would still have to choose which version of Foo the new FooCommon should reference. As said, they are not identical.

A: 

Create an interface containing the common methods:

public interface IFoo
{
   void CommonMethod1();
   void CommonMethod2();
}

Create an abstract base class from IFoo:

public abstract class FooBase : IFoo
{
   // Implement the common calls here
   public void CommonMethod1()
   {
      // concrete shared code goes here
   }
   public void CommonMethod2()
   {
      // concrete shared code goes here
   }
}

Create your one-off code from the FooBase:

public class FooOne : FooBase 
{    
   // concrete code specific to FooOne goes here 
}



public class FooTwo : FooBase 
{    
   // concrete code specific to FooTwo goes here 
}
GalacticJello
Unfortunately I don't think it will work. I still can't have the abstract class in an assembly (as I can't generate a concrete class from it until I know which version of Foo to reference).So where should I place the above? I don't think it can be in its own project. It has to be stored together with the concrete implementation, which is one of the FooOne, ... , FooFour classes.
Binary255
Place IFoo and FooBase in FooCommon.Reference FooCommon in each of your FooOne, FooTwo, etc.
GalacticJello