3 ms·
Does anyone actually do that (for loop to assign a bunch of variables)? To me that just looks like a really awkward way to fake inheritance. Whenever I see the
by overgard 9y ago
Does anyone actually do that (for loop to assign a bunch of variables)? To me that just looks like a really awkward way to fake inheritance. Whenever I see the term "composition" used, at least in my experience, it was just about embedding one object in another. For instance, in a game engine like unity where you do things by composition and components, you would do something like obj.GetComponent<Renderer>() or obj.AddComponent<Thing>() or whatnot. "Composition" still kept the boundaries very well defined.
- Psilidae 9y agoI'm sure this is a thing someone has decided was a good idea at one point. It can easily be done in other languages, too. I wouldn't be surprised if someone, for example, decided to hijack PHP's `__call()` function to forward method calls to a component. Rust has the similar Deref anti-pattern: https://github.com/rust-unofficial/patterns/blob/master/anti_patterns/deref.md https://github.com/rust-unofficial/patterns/blob/master/anti...
- bjterry 9y agoPeople do a morally equivalent thing in Javascript, on occasion. You can use Object.assign() to build an object's functionality from multiple unrelated objects. For example, see the section on concatenative inheritance here: https://medium.com/javascript-scene/master-the-javascript-interview-what-s-the-difference-between-class-prototypal-inheritance-e4cd0a7562e9 https://medium.com/javascript-scene/master-the-javascript-in...