Follow

Thinking about it... in , why are interfaces and traits even different things?

Everything you can do with an interface:

  1. declare functions
  2. extend another interface
  3. "implement" it in a class
  4. use it as a parameter type

Item 1 (functions)

This is functionally the same as defining an abstract public function in a trait.

Item 2 (extend)

This is functionally the same as a trait use-ing another trait.

Item 3 (implementation)

This is functionally the same as use-ing a trait that consists entirely of abstract public functions.

Item 4 (parameter type)

This is the one thing a trait cannot do -- but I don't understand why it was done that way.

Note: this seems related to my trait implements wishlist item from earlier. At first I thought that they might be in conflict, but on looking at the syntax in more depth, I don't see how. A trait that uses/extends another trait is also declaring abstract functions in that trait as an implementation requirement.

Putting both of these suggestions together would both simplify the language and make it more powerful, I'd think.

· · Web · 0 · 0 · 2
Sign in to participate in the conversation
Toot.Cat

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!