On Tue, Jul 11, 2023 at 10:54 AM Michał Marcin Brzuchalski < michal.brzuchal...@gmail.com> wrote:
> Hi Robert, > > wt., 11 lip 2023 o 14:54 Robert Landers <landers.rob...@gmail.com> > napisał(a): > >> ... >> Abstract classes solve this problem perfectly. It's part of the type >> system, it's type-hintable, it's mockable, and it's pretty easy to see >> what inherits it as people who inherit it already know what the base >> behavior was when they wrote the code. >> > > Not exactly, How you wanna solve by abstract class two interfaces > which can be implemented using let's say two traits - let's say > > interface Foo { > public function foo(): string; > } > trait HasFoo { > public function foo(): string { return 'foo'; } > } > interface Bar { > public function bar(): bool; > } > traitHasBar { > public function bar(): bool { return true; } > } > > Now I can need to implement Foo or Bar separately or together. > Using abstract class that would require 3 abstract classes: Foo, Bar, and > FooWithBar. > With this RFC that would require just two interfaces with default methods. > > Now you can easily see how bad this goes if you wanna add 3rd interface. > > Cheers, > Michał Marcin Brzuchalski > > I second this. Imagine a class extends LogAwareAbstractClass. It makes no sense to the type system and it makes it impossible to extend something that actually is part of the domain definition. Interface Default Implementation is an elegant solution that doesn't change the state of PHP while still making things easier and convenient to manage. -- Marco Deleu