When I'm asked in job interview what's an abstract class and how it differs from regular class I reply: You can't create an object from an abstract class. First you need to extend it and it's a job of a regular class. They nod their head and go to next question.
That's a constraint and constraints help programmers think by narrowing down the choices they can make. The job of an abstract class is to always point "North". By "North" I mean responding to property/method calls from classes who (in your case) did not define method addArtikel.
Here is an example from PayPal repository where a class extends an abstract class:
https://github.com/paypal/PayPal-PHP-SDK/blob/ff2a7f9c2ddc47a22cb7bb8a5b0bb97bd16bdd6f/lib/PayPal/Log/PayPalLogger.phpclass PayPalLogger extends AbstractLogger
It so happens that this abstract class also implements a well known interface https://www.php-fig.org/psr/psrPSR-3/ interface.
Here is another example from PayPal where class both extends and implements: https://github.com/paypal/PayPal-PHP-SDK/blob/ff2a7f9c2ddc47a22cb7bb8a5b0bb97bd16bdd6f/lib/PayPal/Common/PayPalResourceModel.php
Here is an example of a loose interfaceclass PayPalResourceModel extends PayPalModel implements IResource
Digging deeper you find this: https://github.com/paypal/PayPal-PHP-SDK/blob/ff2a7f9c2ddc47a22cb7bb8a5b0bb97bd16bdd6f/lib/PayPal/Rest/IResource.php
<?php
namespace PayPal\Rest;
/**
* Interface IResource
*
* @package PayPal\Rest
*/
interface IResource
{
}
Nothing? YesThis example is interesting, because nothing. Programmers have 1000 ways is actually asked of not stepping on their own feet (foot?)programmer who is going to implement this interface. Maximum freedom.
Now, the interface is like a map of a territory, or a todo list for a programmer. It reminds what requirements are. When implementing an interface programmer MUST define all methods listed inside interface file. It throws an error if you skip one. While it's not a case with abstract classes you see.
Going back to your "problem":
AbstractArtikelshould implement an interfaceIArtikeland define fallback functionality.ArtikelLP,ArtikelBookandArtikelBoardgameshould extendAbstractArtikeland redefine methods where appropriate. Here not only similarities, but also differences start to be important.- Create
ArtikelLP,ArtikelBookandArtikelBoardgameobjects.
Can an interface extend an interface? This I don't know.