Sometimes Very often I need a class that implements an interface by making an instance of another class. Sound weird? Let me show you an example. There are many classes of that kind in the Takes Framework, and they all are named like
*Wrap. It's a convenient design concept that, unfortunately, looks rather verbose in Java. It would be great to have something shorter, like in EO for example.
Now, let's take a look at that
RsWrap it extends:
As you see, this "decorator" doesn't do anything except "just decorating." It encapsulates another
Response and passes through all method calls.
If it's not clear yet, I'll explain the purpose of
RsHtml. Let's say you have text and you want to create a
Instead of doing this composition of decorators over and over again in many places, you use
It is very convenient, but that
RsWrap is very verbose. There are too many lines that don't do anything special; they just forward all method calls to the encapsulated
How about we introduce a new concept, "decorators", with a new keyword,
Then, in order to create an object, we just call:
We don't have any new methods in the decorators, just constructors. The only purpose for these guys is to create other objects and encapsulate them. They are not really full-purpose objects. They only help us create other objects.
That's why I would call them "decorating envelopes."