O
O
OOPNoob2019-10-27 18:10:19
PHP
OOPNoob, 2019-10-27 18:10:19

Am I using the abstract Animal class correctly?

abstract Animal {
abstract say()
abstract eat()
}
Dog implements Animal {...}
Cat implements Animal {...}
Cow implements Animal {... and getMilk}
All three classes are similar but the last one adds a method to get milk, Is there a design error, is it possible to say that the cow also implements the Animal class?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Scuba, 2018-08-31
@targetologru

And here, I figured it out. It was necessary to add one more ampersand.

foreach ($by_month as $y => &$months) {
  foreach ($months as $m => &$ers) {
    krsort($ers);
  }
}

S
Sergey, 2019-10-28
@red-barbarian

The question itself provokes: Yes! Wrong! )
But seriously.
Do not build a system from the abstract to the concrete. So good in the tutorial. in reality, this generates many unnecessary layers and classes. Do it from the concrete to the abstract. Those. there are two classes that you apply. they have in common. Take out the general in an abstract class. Those. proceed from the bottom to the abstract.
Second moment. Associated with polymorphism. It's coming up with an interface and then implementing it. But this is a different song.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question