The designers of C# regard MI as Evil. Although I agree with this
generally, I agree that mixins would be useful.
To solve your problem my tendency would be to separate the relevant parts of
the TimeSeries implementation into separate classes and store instances of
those in private fields of a single TimeSeries class based on how the object
is created, i.e. with a constructor like:
public TimeSeries(bool isSeasonable,Ti meSeriesStorage Type storageType) {
if (isSeasonable) {
this.myImplemen tation = new SeasonableTimeS eriesImplementa tion();
} else {
this.myImplemen tation = new NonSeasonableTi meSeriesImpleme ntation();
}
switch (storageType) {
case TimeSeriesStora geType.Memory:
this.myStorageL ogic = new MemoryTimeSerie sStorageImpleme ntation();
case TimeSeriesStora geType.Database :
this.myStorageL ogic = new DatabaseTimeSer iesStorageImple mentation();
default:
throw new NotImplementedE xception(String .Format("Time Series Storage
Type {0} is not implemented.",s torageType));
}
}
.... where TimeSeriesStora geType is an enum:
public enum TimeSeriesStora geType {Memory,Databas e}
Now your internal implementation for various methods would reference the
myImplementatio n or myStorageLogic reference at runtime to access the
appropriate implementation logic.
Probably there are other ways to do this, but that's my $0.02.
--Bob
"PepsiDrink er" <ea***********@ mail.ru> wrote in message
news:6a******** *************** ***@posting.goo gle.com...
Hello! :^)
I am trying to implement a class library for dealing with time series.
I have to use time series with seasonable component and without it.
Also, time series can be stored in memory or in a database.
The problem is to make 4 following classes:
1. non-seasonable and storable in memory
2. seasonable and storable in memory
3. non-seasonable and storable in database
4. seasonable and storable in database
In C++ this problem could be solved by using multiple inheritance. But
I can't inherit class more than from one class in C# and, if I use
interfaces I must write the same implementation of abstract members
myself. For example, if I make an interface ISeasonable, I will need
to write the same code for in-memory and database-storable time
series.
Please, help me to implement my task in C# (if it is possible)
Thanx for attention