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
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.