This is more a question to ease development, as well as a best practice question.
<?php
class FOO implements Iterator
{
....
}
class BAR extends FOO
{
....
}
class OTHER extends FOO implements Iterator
{
....
}
?>
In the above example, would BAR also have the Iterator interface? If so, is it better to define the interface every time anyhow (like OTHER does) or would the BAR definition be considered best practice?
I have simplified this example, as we are using an Abstract Class for FOO, that we want to ensure has Iterator support, which may then be overridden in the BAR class for moving between elements. We want some functions to be forced to be defined for the subclasses, but want to inherit the other methods as appropriate, and still use the basic iterators, without having to define the interface on the child classes.
The subclass will inherit the superclass's implementation of the Iterator interface, which it is free to override. You do not need to explicitly say implements Iterator
, but if you do then you must implement all of the Interface's methods in the subclass.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With