Re: [VOTE] Interface Default Methods
| From: | Robert Landers | Date: | Tue, 11 Jul 2023 14:04:21 +0000 |
| Subject: | Re: [VOTE] Interface Default Methods | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-120775@lists.php.net to get a copy of this message | ||
> 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.
This seems like a software design issue, not a language issue...
But 3 abstract classes vs. 2 interfaces + 2 traits seems like a better
tradeoff if you're going to need the coupling anyway. It's more
obvious that you want/require FooWithBar when you want it. If you're
expecting these exact implementations, moving them to the interface
makes it even more confusing.
I want FooWithBar (iow, I want these exact implementations)
I want Foo&Bar (iow, I don't care about the implementation)
You can pass a FooWithBar to Foo&Bar, but you can't pass a Foo&Bar to
a FooWithBar.
If the default implementation is on the interface ... who knows what
you have, you'll have to check you /vendor folder.