mercredi 28 août 2019

Is NOT using base implementation on a subclass considered 'Refused Bequest'?

I understand that overriding a method and leaving the implementation blank is a refused bequest, but how about when you override a method and don't use the base implementation? Is this considered refused bequest as well?

Example:

public class Car
{
    virtual void Drive()
    {
        // Some kind of drive logic
    }
}

public class Hummer : Car
{
    override void Drive()
    {
        // base.Drive(); - Base drive implementation refused!
        // Some other kind of driving logic
    }
}

Is the following what should be considered acceptable?

public class Hummer : Car
{
    override void Drive()
    {
        // base.Jump(); 
        // Some ADDITIONAL drive logic
    }
}

Aucun commentaire:

Enregistrer un commentaire