I've been reading this Wikipedia article Composition over inheritance. It gives a code example of inheritance first, and then a code example of composition. In case of inheritance there are data that are present in form of the
model field. When any of the methods
update need to do their function, they have access to to the
model field to draw, collide or update it respectively.
In the composition example, this field is prominently absent. The three methods do not have any parameters, and their respective classes have no fields. Where the data that they draw, update or collide come from in case of the composition?
It was pointed out in comments that
model field belongs to the
Visible class. I assumed above that model comes with the "base" class in inheritance terms. Still, conceptually, ditching inheritance means that we are no longer have shared data. I'm trying to understand what people do to exchange these data, since it's reasonable to suggest that
Trap have some common data members required by all those methods, e.g. size, coordinates, etc.