Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4870

Please send help! how to keep your code dry when inheritance is not the answer? composition?

$
0
0

This seems to be so easy, but I always have immense problems to apply it:

I have two different classes and I would like them to have a set of common attributes and methods.

For instance, I both have a book and a song, and I would like them to both have an array with comments, I could use inheritance and put the comments array onto the super class. No problem. However, when I try to apply this pattern a second time, I have a problem, because there is no multiple inheritance in JS. So, I can’t inherit from the comment superclass and for instance from an audio or print superclass.

Now, I sometimes read about composition in that context - however, even finding a good example via google turned out to be pretty difficult. I can see how I would apply composition by using a mixing. I can also see how I could add further things to my class via aggregation. However, how do I compose a class out of multiple attributes and methods the class should have?

Can someone please post a clean example how composing a class (like an ED-model) would look like with E6 classes in the ember octane world?

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 4870

Trending Articles