We've just had a discussion with college about is the following style acceptable for oop or not.
We've a class, which has one public function, and requires a reader in the constructor:
public class Converter
{
private readonly IReader _reader;
public Converter(IReader reader)
{
_reader = reader;
}
public byte[] Convert(...params...)
{
return something;
}
}
We have Reader1 and Reader2 which both implement an IReader.
I want to setup two managers: Converter1 and Converter2, providing the same public Convert() function, but Converter1 will be using Reader1, and Converter2 will use Reader2.
For me the simplest solution is to inherit from Converter and initialize it with proper reader:
public class Converter1 : Converter
{
public Converter1():base(new Reader1())
{}
}
public class Converter2 : Converter
{
public Converter2():base(new Reader2())
{}
}
My college says, that Converter1 and Converter2 are Managers, and inheritance should not be used for managers, instead we should apply a composition here. But from my perspective composition will only result in additional code in specific converters classes.
So, could you please advice, whether it is ok to use inheritance when implementing managers or not? Thanks