Class Implement No More

no-email (Damien Seguy), Damien Seguy
Thu, 07 Nov 2024 00:00:00 +0000

Inheritance forces children classes to have only methods that are compatible with the parent's methods.
The only exception is the constructor, which may have a totally different signature from generation to generation.
Interfaces apply the same constraints: their methods signature must be compatible with the host class. In this case, it also applies to the constructor.
So, in the case a parent class implements an interface with a constructor, and this class has a child class, the child may look compatible with the interface, and yet, be invalid at the constructor level.
Another good reason to avoid placing constructors in interfaces.