SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 31 of 31
  1. #26
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Do note,

    program to an interface, not an implementation
    Again, I must point out: the term "interface" has two different meanings. One is "public methods of a class", and that is what is meant in the quote, and I completely agree with that. However, the other meaning is for "syntactic construct" of a language that sets the restriction -- and I'm all against that in a dynamic language like PHP.

  2. #27
    throw me a bone ... now bonefry's Avatar
    Join Date
    Nov 2004
    Location
    Romania
    Posts
    848
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Do note,

    program to an interface, not an implementation
    That rule is good for static languages (Java). Because in a static language, it's more usefull to brake complex classes into simpler classes, and when applying inheritance, the real usefullness of the inheritance schema is when inheriting the interface.

    But in a dynamic language, the implementation should be favored because the interface is most of the times useless. That is why I think PHP should've had multiple inheritance.

    Also I stated in a previous thread that in PHP interfaces are broken i.e. they are implemented as some kind of abstract classes. So the interpreter issues an error if 2 inherited interfaces share 1 function signature. And that's just stupid.

  3. #28
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is why I think PHP should've had multiple inheritance.
    There are any number of problems with Multiple Inheritance, such as the well known 'diamand' problem for example?

    Interfaces prevent this from ever happening. Do a search on www.javaworld.com on the term of Multiple Inheritance, and you'll learn (quickly) why Java doesn't support this, and then come back to this thread, and say you (still) think that PHP should support it.

    PHP is not Java certainly, but regardless of the language or technology, Multiple Inheritance is bad, bad and just bad.

  4. #29
    SitePoint Zealot
    Join Date
    Jul 2005
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, multiple inheritance isn't great at all. You can of course emulate it, if you really want it

  5. #30
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    There are any number of problems with Multiple Inheritance, such as the well known 'diamand' problem for example?
    When creating a language implementation, that's pretty easy to solve. When a class inherits several parents, and more than one of them has a certain method, just use the implementation in the latest class declared.

    For example:

    PHP Code:
    class Foo
    {
        function 
    bluff()
        {
            
    // bluff code
        
    }
    }

    class 
    Bar
    {
        function 
    bluff()
        {
            
    // bluff code
        
    }
    }

    class 
    Muffin inherits FooBar
    {

    Muffin::bluff() would inherit Bar::bluff().

  6. #31
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Location
    United Kingdom
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BerislavLopac
    When creating a language implementation, that's pretty easy to solve. When a class inherits several parents, and more than one of them has a certain method, just use the implementation in the latest class declared.

    For example:

    PHP Code:
    class Foo
    {
        function 
    bluff()
        {
            
    // bluff code
        
    }
    }

    class 
    Bar
    {
        function 
    bluff()
        {
            
    // bluff code
        
    }
    }

    class 
    Muffin inherits FooBar
    {

    Muffin::bluff() would inherit Bar::bluff().
    What if you wanted to have one method from Foo and one from Bar that existed in both? Afaik, languages that support MI generally use a method by method means of determining which classes method gets used. Personally, I think MI adds a level of complexity that outweighs any usefulness.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •