Solution Idea
I would use an Interface Layer for this (called Project I
).
This Project I
contains the interface ICar
.
The other Projects A
, B
and C
reference to I
.
Your Car class should implement this interface and look something like this:
public class Car : ICar
{
// ... some great Code
}
In Project B
your function would be:
public List<ICar> GetCars()
{
var myCars = new List<Car>();
// ... some really special magic
return (List<ICar>)myCars;
}
Now your code, in project C
can use this function like this:
List<ICar> cars = B.GetCars();
Why using an Interface Layer?
Because then you will gain more maneuverability in your code. This is great for using Dependency Injection or Unit Tests. It will help you replace parts of your implementation in certain situations for example providing Mock objects during Unit Testing.
Design Approach
To prevent spaghetti code
i would recommend to look up Jeffery Palermo's concept of Onion Architecture.
There are some great Question about it on SO: