Jump to content

Interfaces in PHP5 : need to explicitly "implement" on child classes?


Zearin

Recommended Posts

I've not too far into building my first framework (OOP) in PHP5, and I'm using Doxygen to generate documentation for it.

I have a question about interfaces: If a parent class implements an interface, must all descendant classes explicitly say "implements InterfaceName" as well? 

If it is not strictly required, is it considered desirable in the interests of Best Practices?

The reason I ask is that I have a small hierarchy consisting of three classes:

      Parent
|-------+------|
Child1            Child2


I have all 3 classes explicitly stating "implements InterfaceName".  However, Doxygen is generating a confusing result for me: although it seems to recognize that my interface is an interface and not a class, it builds the inheritance diagram as follows:


                  Interface
                       +
       +------------|-------------+
     Child1        Parent          Child2
                        +
            |----------------------|
         Child1                   Child2


So yeah.  Doxygen's fault?  Mine?  Nobody's? 

Most importantly, I'm interested in Best Practices. :D
[quote]I have a question about interfaces: If a parent class implements an interface, must all descendant classes explicitly say "implements InterfaceName" as well? [/quote]

No.

Avoid multiple levels of inheritance, only the parent class need specify the interface.

Correct diagram should like this:

                  Interface
                      +
                    Parent
                        +
            |----------------------|
        Child1                  Child2

Child classes can implement other interfaces in addition.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.