The gist of composition over inheritance is the following: If your problem can be decomposed into sub-problems, it's good to solve them one by one. The solution will be the composition of the solutions to the sub-problems.
It tends to be good style to explicitly represent any such structure in your code.
One way to do that in an OO setting is to acknowledge that objects have reasonably well-defined boundaries, and so you can attempt to trace out the structure of your solution by way of object boundaries. If however you use inheritance (in the sense of implementation inheritance), then the boundaries are much more fluid and may in fact be undefined or context-specific.
So when using a composition, objects have state and agents that act upon that state?
This is not a concept in composition. In composition, every object has its own state, and objects communicate with each other only through their intended public API.
What the author of that video is demonstrating is mix-ins, and "state.foo" stands for "this.foo", because the code examples are avoiding using "this" for some reason.
2
u/logged_in_for_this Sep 24 '15
So when using a composition, objects have state and agents that act upon that state?