Can I combine composition and inheritance with interfaces in C #

I have a design problem that I cannot understand. Here is what I have:

In general, I have two general types of objects: Strikes and Parameters. They were abstracted on two interfaces IStrike and IOption.

Let's say that IOption has the following fields, in reality there are about 10 times as many, but we can use the following three to illustrate the problem.

interface IOption
{
   double Bid{get;set;}
   double Ask{get;set;}
   double ImpliedVol{get;set;}
}


interface IStrike
{
   IOption Call{get;set;}
   IOption Put{get;set;}
}

So, all is well and good, but let me say that I have the following method for doing some “math” in IOption implied vol

public double SquareImpliedVol(IOption opt)
{
   return Math.Pow(opt.ImpliedVol,2);
}

, , - , , Bid Ask. , , SquareImpliedVol, , , .

, , IOptionImpliedVol, ImpliedVol, IOption IOptionImpliedVol, ,

interface IOption : IOptionImpliedVol
{
   double Bid{get;set;}
   double Ask{get;set;}
}

SquareImpliedVol

public double SquareImpliedVol(IOptionImpliedVol opt)
{
   return Math.Pow(opt.ImpliedVol,2);
}

. , . .... , List, , IStrike, Call.ImpliedVol Put.ImpliedVol. -

interface IStrikeImpliedVol
{
   IOptionImpliedVol Call;
   IOptionImpliedVol Put;
}

interface IStrike : IStrikeImpliedVol
{
   IOption Call;
   IOption Put;
}

, . , - , , - .

+5
2

, . , , Bid/Ask ​​ .

. (, SquareImpliedVol ). , ImpliedVol, Bid/Ask, . unset Bid/Ask, - - . , , Bid/Ask Option, .

, , , , , , .

+5

, - , , - .

, " -, IOption" , , , , IOption . , , , , , , , :

var mock = CREATE MOCK OF TYPE IOption
ON MOCK mock, EXPECT CALL TO ImpliedVol
    FOR THAT CALL, RETURN 15

test code

VERIFY THAT CALLS WERE MADE AS EXPECTED

, , ​​ NMock , . , " Bid ", .

-, . , , . , , ? , , - . , , , , .

?

0
source

All Articles