4
4
4sadly2020-04-20 12:09:10
PHP
4sadly, 2020-04-20 12:09:10

Why do they do it?

Why create an interface if the methods will work anyway?
Why do this:

interface Walking{
    public function walk();
}
interface Swimming{

    public function swim();
}
class Dog extends Animal implements Walking {

    public function walk()
    {
        // TODO: Implement walk() method.
    }
}
class Penguin extends Animal implements Walking, Swimming{

    public function walk()
    {
        // TODO: Implement walk() method.
    }

    public function swim()
    {
        // TODO: Implement swim() method.
    }
}

If possible like this:
class Dog extends Animal{

    public function walk()
    {
        // TODO: Implement walk() method.
    }
}
class Penguin extends Animal{

    public function walk()
    {
        // TODO: Implement walk() method.
    }

    public function swim()
    {
        // TODO: Implement swim() method.
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2020-04-20
@4sadly

An interface GUARANTEES the existence of such a method in a class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question