6 kyu

Object-Oriented PHP #8 - Interfaces [Advanced]

Description
Loading description...
Object-oriented Programming
Fundamentals
Tutorials
  • Please sign in or sign up to leave a comment.
  • Itsacon Avatar

    It's worth noting that this part of the description:

    The only condition where implementing multiple different interfaces is mutually exclusive is if the two (or more) interfaces in question share a public method with the exact same name. In that particular case, if you implement both such interfaces at once, you will receive a Fatal error (since the "Diamond Problem" would arise which would create a conflict).

    is not (or no longer) correct. As long as both methods follow signature compatibility rules, a class can implement two interfaces describing methods with the same name.

    So the two interfaces in the exercise that overlap are actually compatible, as the methods are identical.

  • Glebowsky Avatar

    Failed asserting that two strings are identical. Expected: 'Hello Benjamin, how are you?' Actual : 'Hello Donald, how are you?'

    why does the $name variable take values from another class?

  • Glebowsky Avatar

    Failed asserting that null is identical to 'Barry'. Failed asserting that null is identical to 'Donald'.

    what am I doing wrong?

  • khlivnyuk Avatar

    Donald, you are awesome katamaker! So much work have been done to create these serieses. I wish more PHP katas in this conscientious and consistent way.

  • thekaylez Avatar

    Just finished! Thank you for this kata series!!!! This is the best I've come across with PHP. You have no idea how much I've learned from doing these.
    I appreciate them and hope there's more!

  • nvlnvl Avatar

    Cheers for the series, very helpful!

  • Sejiko Avatar

    i like this kata series and im awaiting the function series^^. But i have a question for what do you need interfaces if you doing your job correctly...
    Its 100 times more work where you can make more mistakes.

    • donaldsebleung Avatar

      Glad you're enjoying my Kata Series :D

      As discussed in the Lesson in this Kata, various advantages of interfaces include:

      • Unlike (parent) classes where a child class can only inherit from one parent class, a class can implement multiple interfaces so that two different classes can share similar methods and behaviour yet have other different properties, methods and behaviour
      • In large project where a large number of interrelated classes are present, interfaces can ensure that certain methods common to multiple classes have the exact same argument list so when you use a method of the same name from different classes, you do not have to worry about passing in different types of arguments or passing in the arguments in a different order depending on the instance of the class that the object belongs to - this makes editing your code easier as you are less likely to make mistakes when/if you change an object from being an instance of a class to being an instance of another (closely) related class
      • Another major advantage of interfaces is realised when you are working on a PHP project involving multiple classes as a team of developers. By defining certain interfaces and requiring your colleagues to implement certain interfaces when they program the classes, it ensures that in the future when the classes are complete and when you use an instance of one of the classes, you automatically know the order and nature of the argument list of certain methods which again reduces the number of mistakes in collaboration.

      That being said, if you are working on a small PHP project by yourself which involves only one or two classes, it is unnecessary and indeed bad practice to define interfaces for those classes to implement.

      Hope this answers your question :D

  • mn113 Avatar

    Thanks for the hard work. This episode required a lot of careful typing by the student AND the course creator!

  • smile67 Avatar

    Generally nice series (perhaps a little bit long this one;-)), so many thanks for your effort! I would like to see some "PHP things without OOP" (or not as main and only point), like "normal/useful PHP commands, statements a.s.o" (PHP basics) needed for "usual programs or katas" - i think you know what i mean;-).

    • donaldsebleung Avatar

      This series will probably end after one or two more Kata. After that, I'm thinking of perhaps starting a new series on PHP Functions ;)

    • smile67 Avatar

      Sounds good, i'm curious about it;-)! And i'm sure for the next part (PHP Functions) you quicker will get more code/solutions too (so perhaps more motivation for you;-))...