Crell / enum-comparison

A comparison of enumerations and similar features in different languages
82 stars 7 forks source link

Allow implementing interfaces in enum cases #34

Closed iluuu1994 closed 3 years ago

iluuu1994 commented 3 years ago

Enum Cases may not implement interfaces themselves.

Since we allow implementing methods that are only available in a subset of the cases allowing to implement interfaces only for a subset of cases would probably also make sense.

Crell commented 3 years ago

Not a hill I'll die on either way. Mainly I'm just trying to balance "make enums as powerful as possible" without becoming "there's really no reason to not just use objects". :smile:

dbalabka commented 3 years ago

@iluuu1994, @Crell then I would propose to implement abstract methods to be available for Enum class as well. It might give a possibility to easy control methods implementation for each case w/o introducing new interface:

enum SomeEnum {

    case FirstCase {
        public function color() {}
    }

    case SecondCase {
        public function color() {}
    }

    abstract public function color();
}
iluuu1994 commented 3 years ago

This is now irrelevant.