3 ms·
So true. Generally, whichever one best matches the feeling best is how I go. Some things really feel like objects, they've got little personalities, friends,
by seph-reed 7y ago
So true. Generally, whichever one best matches the feeling best is how I go.
Some things really feel like objects, they've got little personalities, friends, parents... a whole list of talents and characteristics. OOP it is.
Other things are more like physics. It doesn't really need to have a name to exist, there doesn't need to be a container, it always acts predictably. Time to get functional.
I've also been using a tactic which I have no idea what it's really called, but I call it augmentation. I think of them like those crystals you add to your weapons in diablo or other RPGs. The gist is: a public readonly member which takes the object that holds it as an argument and has extra functionality. So like:
```
class Staff {
public readonly flamePower = new FlameAugment(this);
}
(new Staff()).flamePower.doSomethingSpecialInvolvingStaff();
```
- duncan-donuts 7y agoWouldn’t that just be a form of inversion of control? It feels a lot like dependency injection, though maybe I’m misunderstanding from the example.
- seph-reed 7y agoDefinitely like a form of inversion of control. Wouldn't think to call it that because the inversion is so shallow, and the control is always accessed from the context of the typical controller. It doesn't feel like what I use IOC for, though there is a similarity.
- Jtsummers 7y agoFYI: Code markup on HN works with two spaces at the start of the line, your example is probably meant to look more like this: class Staff { public readonly flamePower = new FlameAugment(this); } (new Staff()).flamePower.doSomethingSpecialInvolvingStaff();
- vereis 7y agoIsn't this basically what an Entity Component system is?
- seph-reed 7y agoBingo. Just looked it up, and that looks like exactly what I'm talking about. I can't say for certain as I haven't ever used/read code that was described as an Entity Component system, so there may be some crucial differences I'm overlooking. But I'm pretty sure you nailed it. EDIT: Just read into this a bit more (http://vasir.net/blog/game-development/how-to-build-entity-component-system-in-javascript http://vasir.net/blog/game-development/how-to-build-entity-c...). It's something different. Kind of a mix between this and IOC.
- tigershark 7y agoI think that you mean the Decorator pattern
- seph-reed 7y agoIt's like decorator. My experience with decorators are that they modify prototype, which is something I'm not a fan of. They also have a tendency to create too many layers, like overused inheritance.
- machiaweliczny 7y agoThis way of doing mixins is nice, reliable, testable way of reusable logic and works well with structural type system. I think going this obvious way would be better than hooks for React. We will see.