Liskov substitution and abstract classes / strategy pattern
- by Kolyunya
I'm trying to follow LSP in practical programming. And I wonder if different constructors of subclasses violate it. It would be great to hear an explanation instead of just yes/no. Thanks much!
P.S. If the answer is no, how do I make different strategies with different input without violating LSP?
class IStrategy
{
public:
virtual void use() = 0;
};
class FooStrategy : public IStrategy
{
public:
FooStrategy(A a, B b) { c = /* some operations with a, b */ }
virtual void use() { std::cout << c; }
private:
C c;
};
class BarStrategy : public IStrategy
{
public:
BarStrategy(D d, E e) { f = /* some operations with d, e */ }
virtual void use() { std::cout << f; }
private:
F f;
};