D
Daniel Billingsley
The base class obviously can't know anything about a class which inherits
from it, but is it acceptable to have a base class method which will be
given information from an inherited class?
For (a stupid) example:
-----------
public abstract class BaseClass
{
private int _someInteger=0;
protected int AddNumbers(int anotherNumber)
{
return anotherNumber + _someInteger;
}
}
public class Class2 : BaseClass
{
private int _anotherInteger;
public int GetANumber()
{
return base.AddNumber(_anotherInteger);
}
}
----------
The underlying issue is that the generic code in the AddNumbers method from
example is known to be needed in all the classes inheriting from BaseClass,
but needs some additional information based on the specifics of the
inherited class (it's a data access method in reality).
from it, but is it acceptable to have a base class method which will be
given information from an inherited class?
For (a stupid) example:
-----------
public abstract class BaseClass
{
private int _someInteger=0;
protected int AddNumbers(int anotherNumber)
{
return anotherNumber + _someInteger;
}
}
public class Class2 : BaseClass
{
private int _anotherInteger;
public int GetANumber()
{
return base.AddNumber(_anotherInteger);
}
}
----------
The underlying issue is that the generic code in the AddNumbers method from
example is known to be needed in all the classes inheriting from BaseClass,
but needs some additional information based on the specifics of the
inherited class (it's a data access method in reality).