"Pohihihi" <
[email protected]> a écrit dans le message de %
[email protected]...
| Solution is nice, and someone should should have done like that but then
| still it do not solves my current problem of living with base class which
we
| have to use. Basically I am looking for a way to override base abstract
| class that do not take arguments. I need to hide that and put my own
| override to take an argument. I can't hide public methods in base class as
| it is a derived class, and can't create object and use it internally in
the
| child class as base class is very full of stuff needed and it will be a
| 80-90 % rewrite of it. Also can't add method in base class.
Yes, aggregation does solve your problem in that it allows you to hide
properties/methods that are not suitable behind a wrapper class. If your
base class is abstract then simply derive from that and override all the
abstract stuff in a meaningful way, then include an instance of the derived,
non-abstract class in the wrapper class.
You cannot hide public methods, in the base class but you can use the
aggreagation technique to create a wrapper class which will allow you to
hide the entire declaration of the class and only expose what you want in
the wrapper class. You don't have to rewrite a whole class, just write
methods/properties in the wrapper class that access the base or derived,
non-abstract class
public abstract class BaseClass
{
public abstract void NoArgsMethod();
}
public class DerivedClass : BaseClass
{
public override void NoArgsMethod()
{
// empty method
}
}
public class WrapperClass
{
private BaseClass baseObj = new DerivedClass();
public void ArgsMethod(int arg, string anotherArg)
{
// do what you want, calling baseObj as required
}
}
Joanna