Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing implicit conversion as a substitute for multiple inheritance in .NET
    text
    copied!<p>I have a situation where I would like to have objects of a certain type be able to be used as two different types. If one of the "base" types was an interface this wouldn't be an issue, but in my case it is preferable that they both be concrete types.</p> <p>I am considering adding copies of the methods and properties of one of the base types to the derived type, and adding an implicit conversion from the derived type to that base type. Then users will be able treat the derived type as the base type by using the duplicated methods directly, by assigning it to a variable of the base type, or by passing it to a method that takes the base type.</p> <p>It seems like this solution will fit my needs well, but am I missing anything? Is there a situation where this won't work, or where it is likely to add confusion instead of simplicity when using the API?</p> <p><strong>EDIT:</strong> More details about my specific scenario:</p> <p>This is for a potential future redesign of the way indicators are written in <a href="http://www.rightedgesystems.com/" rel="nofollow noreferrer">RightEdge</a>, which is an automated trading system development environment. Price data is represented as a series of bars, which have values for the open, low, high, and close prices for a given period (1 minute, 1 day, etc). Indicators perform calculations on series of data. An example of a simple indicator is the moving average indicator, which gives the moving average of the most recent <em>n</em> values of its input, where <em>n</em> is user-specified. The moving average might be applied to the bar close, or it could be applied to the output of another indicator to smooth it out.</p> <p>Each time a new bar comes in, the indicators compute the new value for their output for that bar.</p> <p>Most indicators have only one output series, but sometimes it is convenient to have more than one output (see <a href="http://en.wikipedia.org/wiki/MACD" rel="nofollow noreferrer">MACD</a>), and I want to support this.</p> <p>So, indicators need to derive from a "Component" class which has the methods that are called when new data comes in. However, for indicators which have only one output series (and this is most of them), it would be good for them to act as a series themselves. That way, users can use <code>SMA.Current</code> for the current value of an SMA, instead of having to use <code>SMA.Output.Current</code>. Likewise, <code>Indicator2.Input = Indicator1;</code> is preferable to <code>Indicator2.Input = Indicator1.Output;</code>. This may not seem like much of a difference, but a lot of our target customers are not professional .NET developers so I want to make this as easy as possible.</p> <p>My idea is to have an implicit conversion from the indicator to its output series for indicators that have only one output series.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload