THESE FORUMS ARE NOW FROZEN
Please choose "Forums" from the Main menu of www.entityspaces.net to get to our new forums.

Polymorphism in ES

rated by 0 users
This post has 3 Replies | 1 Follower

Top 75 Contributor
Posts 36
crickard Posted: 06-15-2009 11:03 AM

Hi,

I have three ES classes that map to SQL Server views with the same fields/columns (I don't have access to underlying data only these three views).  I'd like to create a object reference that I can use with an instance of any of the three classes.  Here is what I am basically trying to do (switch used for demo purposes only):

Code:
esEntityCollection strategyColl;

switch (PortfolioID)
{
   case COMPOSITE_CAPAPP:
          strategyColl = new PvwPerformanceCompositeGrowthCollection();
   case COMPOSITE_VALUE:
          strategyColl = new PvwPerformanceCompositeValueCollection();
   case COMPOSITE_SM_CAP:
          strategyColl = new PvwPerformanceCompositeSmallCapCollection();
}

try
{
    strategyColl.Query.Load();
}
catch (Exception ex)
{
    Debug.WriteLine(ex.ToString());
}

where the class declarations look like this:

Code:
public class PvwPerformanceCompositeGrowthCollection : 
   esPvwPerformanceCompositeGrowthCollection, IPerformanceCollection, IEnumerable


public class PvwPerformanceCompositeSmallCapCollection : 
   esPvwPerformanceCompositeSmallCapCollection, IPerformanceCollection, IEnumerable


public class PvwPerformanceCompositeValueCollection : 
   esPvwPerformanceCompositeValueCollection, IPerformanceCollection, IEnumerable
 

Here is the IPerformanceCollection interface:

Code:
    public interface IPerformanceCollection
    {
        int MostRecentYear { get; set; }

        double? CompositeCumulativePerformance();
        double? CompositeDollarInto();
        double? CompositeFiveYears();
        double? CompositeOneYear();
        double? CompositeSinceInception();
        double? CompositeTenYears();
        double? CompositeThreeYears();
        double? CompositeYTD();
        DateTime? GetBeginDate(int Year, int Quarter);
        int GetMostRecentYear();
        double? RussellCumulativePerformance();
        double? RussellDollarInto();
        double? RussellFiveYears();
        double? RussellOneYear();
        double? RussellSinceInception();
        double? RussellTenYears();
        double? RussellThreeYears();
        double? RussellYTD();
        double? SP500CumulativePerformance();
        double? SP500DollarInto();
        double? SP500FiveYears();
        double? SP500OneYear();
        double? SP500SinceInception();
        double? SP500TenYears();
        double? SP500ThreeYears();
        double? SP500YTD();

        public enum MarketIndex
        {
            COMPOSITE = 0,
            SP500 = 1,
            RUSSELL = 2,
        }
    }

 

Is there a class I can use to define strategyColl? I've tried using several classes and I get errors at complie time like this:

Code:
esEntityCollection strategyColl;
strategyColl.Query.Load();

'EntitySpaces.Core.esEntityCollection' does not contain a definition for 'Query' and no extension method 'Query' accepting a
first argument of type 'EntitySpaces.Core.esEntityCollection' could be found (are you missing a using directive or an assembly reference?)

Of course, the esEntityCollection class doesn't define the methods in the IPerformanceCollection interface, so the other error I'll see is:

Code:
lblIndexYTD.Text = DisplayPerformance(strategyColl.RussellYTD());

EntitySpaces.Core.esEntityCollection' does not contain a definition for 'RussellYTD' and no extension method 'RussellYTD' accepting a first argument of 
type '
EntitySpaces.Core.esEntityCollection' could be found (are you missing a using directive or an assembly reference?)
I need a combination of both (I really need C++'s multiple inheritance capabilitiy) since all three classes have the same interface.  Any ideas?
Top 200 Contributor
Posts 14

Try

esEntityCollection strategyCol;

strategyColl.es.Query.Load()

 

Top 10 Contributor
Posts 3,881

Can you tell me at a high level what exactly you're trying to accomplish? If I knew that I bet I could help you. We have the ability for you to create Custom bases classes that slice in between ours and yours, you can also set the Query.es.QuerySource to make a single query hit all three views, there are many options but I'm not sure what you're after.

 

EntitySpaces | Twitter | BLOG | Please honor our Software License

Top 75 Contributor
Posts 36

I'm looking to create a class that has the ES methods exposed along with the interface that I've described above.  This data is stored in SQL Server so I can access it but I have to use the data as is because there is a commercial software application that uses it.

 From the problem domain's standpoint, I have to report on financial performance data.  This data is always going to be periodic.  So I may have underlying data that I need to determine what the performance of a mutual fund or investment strategy for the past 3 months, 6 months, 9 months, 1 year, 3 years, etc.  The point is those performance reporting periods are the same but the underlying view will be different for each.  Consequently, the object will use the same interface that tI posted above.

I hope that's an adequate explanantion.  Thanks for your help!

 Chris

 

Page 1 of 1 (4 items) | RSS
Copyright © 2005 - 2009, EntitySpaces, LLC