T
Trans
On the other hand, if you're reusing them in multiple places, e.g.:
class FooWithBarAndBaz
include Foo
include Bar
include Baz
end
class FooWithBarAndHoge
include Foo
include Bar
include Hoge
end
...you've got to create a distinct class up front for every permutation
of features. If you were composing objects instead, you'd be able to
compose objects dynamically, instead of being limited to the particular
compositions that you've baked into classes.
How would you do it? Ok, say we create classes for everything instead,
then how do create this dynamic composer? Is it a factory?
FooWithBarAndHoge = Composer.factory(Foo, Bar, Hoge)
So what's really that difference between this and the above? Or do you
have something else in mind?
Seems like in the end it's formally equivalent no matter how we do it,
only the underlying implementation differs. Of course there are
different trade-offs to consider for different implementations. But I
doubt any one is better than another in all ways. For instance using
delegation, we initialize four new objects in memory for every one
FooWithBarAndHoge, depending on what's more important to us, that
might not be as desirable.
I've come to recognize a tying of the internal representation to the
serialized form as a code smell, because usually (especially) when the
serialized form is designed to be human-editable, the requirements for
the structure of the two can be very different.
There doesn't need to be just one representation for all cases, does
there? A one-to-one map is great for a first layer. Then an adapter
can be created for any different internal representation that's
needed. But in my case, the whole point of the class is really to
provide read-access to that serialized data.
T.