I have a series of objects that I have mapped into a database with LINQ to SQL. The tables are highly normalized. I’m going to abstract my problem. I have five central entities that I have implemented in the database. I then have a series of other objects which I want to implement one or all of these five entities.
Suppose I am implementing a sort of stadium class (think sports teams). These five entities are the five major sports; Baseball, Basketball, Football, Hockey, Soccer. I want to explicitly implement a class for each stadium.
This is an example, Yankee Stadium has hosted Baseball, Hockey and Football games. I want it to implement each of those 3 interfaces. The StadiumBaseClass is my abstract base class that interfaces with my database. The StadiumBaseClass implements all 5 major sports interfaces. I don’t want to have the same code for implementing the IBaseball interface in all possible stadiums, I want it to be implemented once in StadiumBaseClass.
I this example, I only want to implement 3, is this the best way of doing this? Its sort of singletonish, but not quite?
class YankeeStadium : IBaseball, IHockey, IFootball
{
StadiumBaseClass _Stadium {get; set;}
// IBaseball
public IBaseball.Whatever {get { return _Stadium.Baseball;} }
// IFootball
public IFootball.Whatever {get { return _Stadium.Hockey;} }
// IHockey
public IHockey.Whatever {get { return _Stadium.Hockey;} }
}
Here’s an alternative approach (we have used something similar, but not sure how well it will correspond with your linq implementation):
Have StadiumBaseClass implement each of the interfaces with base functionality, then expose virtual properties that the implementing classes can use to a) indicate which interfaces it supports and b) alter the default behavior as needed.
For example, assuming the following interfaces:
Your base class would look something like:
Which would leave your individual stadium class as: