jeudi 26 avril 2018

Overriding virtual boolean pure method without LSP breaking

For example we have the following structure:

class Base
{
    [pure]
    public virtual bool IsValid(/*you can add some parameters here*/)
    {
       //body
    }
}

class Child : Base
{
    public override bool IsValid(/*you can add some parameters here*/)
    {
       //body
    }
}

Could you please fill Base::IsValid() and Child::IsValid() with different bodies but without conflicts with LSP? Let's imagine it's just method for analyzing, we cannot change instance's state. Are we able to do it? I'm interested in any example. I try to understand whether virtual (bodied) boolean methods is anti-pattern or not in general case.

Aucun commentaire:

Enregistrer un commentaire