Liskov substitution and abstract classes / strategy pattern
        Posted  
        
            by 
                Kolyunya
            
        on Programmers
        
        See other posts from Programmers
        
            or by Kolyunya
        
        
        
        Published on 2012-12-10T07:11:05Z
        Indexed on 
            2012/12/10
            11:23 UTC
        
        
        Read the original article
        Hit count: 399
        
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;
};
        © Programmers or respective owner