the implementer class ‘thefoo’ takes an integer from its constructor. but the base class ‘foo’ can not see its constructor value ‘input’. because the base ctor works first. i’m need of some way to tell the base that implementer’s ctor value. without changing the base can i make passed the following failingtest?
public abstract class foo
{
int noImplementerKnowsThatValue = 0;
protected abstract int intro();
protected abstract int outtro();
public foo()
{
noImplementerKnowsThatValue += intro ();
}
public int compose ()
{
return noImplementerKnowsThatValue + outtro ();
}
}
public class theFoo : foo
{
int value;
public theFoo (int input)
{
value = input;
}
protected override int intro ()
{
return value;
}
protected override int outtro ()
{
return 100;
}
}
public class fooTest
{
public void failingTest ()
{
var foo = new theFoo (100);
int x = foo.compose ();
Debug.Assert (200 == x);
}
}
You can’t. Not unless you change the base class.
Well, I suppose you could make
But I think that’s not what you mean. And it doesn’t solve the general case of this problem (for instance, if instead of
intthere would bestring).