If you have traits, do you stop using interfaces, abstract base classes, and multiple inheritance?

It seems that Traits can completely replace interfaces, abstract base classes, mixins and multiple inheritance, leaving you only traits and specific inheritance.

Is that an intention?

If you have traits, which of the other code structuring constructs should you use?

(Roles are the name of Perl for hell.)

+4
source share
4 answers

I cannot use interfaces or abstract classes at the moment, but mixins and multiple inheritance are really activated by signs, so it’s highly recommended to use these paradigms here. Check out the entire collection library to see very rich classes that you can use using these ideas.

And, my comments reflect Scala - I did not know that you noted this in several languages.

+1
source

At least for Perl Moose, there are no interfaces, so the roles are clearly divided into them, and in general mixins too. I would say that there may still be a case for abstract base classes. Roles can be considered do objects, where classes are the ones in which they .

For this line of reasoning, use for an abstract base class may still be acceptable. One example is a URL. For a URL, it can be an abstract base class. The I / O stream may differ, perhaps better as a role, because it determines how things behave, rather than what they are.

However, when using roles, I still do not see a clear need for true multiple inheritance from more than one class.

+2
source

When you define a trait; he consumes one class. So regardless of expressiveness; You can use an outdated design to prevent the explosion of classes in your bank (and start time).

I will let others answer the question of expressiveness :)

0
source

I am only talking about Scala here ...

Read this .

0
source

All Articles