Interface - PHP - P61

Published: 18 June 2020
on channel: Dino Cajic
182
4

The topic of interfaces. An interface resembles an abstract class but there are a few differences. With the abstract class, you can create method declarations and implemented methods. Child classes can then inherit an abstract class and override or implement its methods. With an interface, you can only define the functionality. You can’t actually implement anything.

The biggest difference is that a child class can only extend one abstract class but it can implement multiple interfaces. You will hear the term contract when talking about interfaces meaning that once you implement it, you are obligated to define each method that was declared inside the interface.

Our Mammal class is a perfect example of an abstract class. There are certain methods that all mammals share, and do it the same way, so it’s a good idea to actually implement those methods there. I would argue that the Animal class makes a good candidate for an interface. Why? Because although all animals share certain similar traits, they each differ based on the animal.

So, you should force child classes to implement those methods. Interfaces begin with the keyword interface and the methods inside the interface are all abstract. You don’t have to use the abstract keyword. To implement the interface, you use the implements keyword, not the extends keyword.

Read the full article on my website
https://www.dinocajic.com/php-interface/

Code for this tutorial
https://github.com/dinocajic/php-7-yo...

Full Code
https://github.com/dinocajic/php-7-yo...

PHP Playlist
   • PHP Tutorial  

--
Dino Cajic
Author and Head of IT

Homepage: https://www.dinocajic.com
GitHub: https://github.com/dinocajic
Medium:   / dinocajic  
Instagram:   / think.dino  
LinkedIn:   / dinocajic  
Twitter:   / dino_cajic  

My Books
An Illustrative Introduction to Algorithms
https://www.amazon.com/dp/1686863268

Laravel Excel: Using Laravel to Import Data
https://amzn.to/4925ylw

Code Along With Me - PHP: From Basic to Advanced PHP Techniques
https://amzn.to/3M6tlGN


On this page of the site you can watch the video online Interface - PHP - P61 with a duration of hours minute second in good quality, which was uploaded by the user Dino Cajic 18 June 2020, share the link with friends and acquaintances, this video has already been watched 182 times on youtube and it was liked by 4 viewers. Enjoy your viewing!