-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MatcherEnvelope and TextMatcherEnvelope are just inheritance hidden behind EO names #135
Comments
@llorllale/z please, pay attention to this issue |
@llorllale in a way this is similar to yegor256/cactoos#947 and the solution that was implemented there. |
Please elaborate.
If this is the reason then the counter is that the interface contracts specify (or should) specify behavior applicable across all implementations. Eg. "all You might argue: we can implement a "ComparableText" or something similar. Someone might counter with a usability argument. I'm not sure. |
Sorry, it is badly phrased, I should have said But let me clear: I don't say you shouldn't be using inheritance, I am saying that if you do, please don't call the parent class
The problem with this is that the ONLY way to reuse that common behaviour, is to inherit from I didn't think about this example before, but with inheritance, you loose the capacity to compose multiple decorator together also.
The usability argument is moot to me, see again the discussion in yegor256/cactoos#1154 (comment) for that, I don't think it is really less usable in terms of typing stuffs, and the advantages are greater if you use composition over inheritance. |
@llorllale arg, I again forgot to ping you in the above comment, sorry, not my day today :) it's fixed |
I posed the question to yegor on this blog: http://disq.us/p/234j0ov Here's how I see it:
|
@llorllale I'm sorry but I think you are missing the point. I have been successfully be using envelopes as I describe them and everything you just said in that comment is not related to the question of envelopes.
Yes: however a
Yes, but it's tangential to the discussion here, I don't see why you bring that up.
I agree with you that it is, I never said the opposite, I don't understand why you try to convince me of something I already agree with. I would add the following: if
Yes, we agree: the only way to extend
No, it's incorrect, if you directly implement Finally:
You posed a good question, but it's a vain question because our I'm just asking for those separate things, and maybe you can decide to only apply some, I don't know:
|
@paulodamaso for the record, in cactoos things went forward with having pure envelopes and common features in the real implementation instead of abstract classes, see yegor256/cactoos#947 |
@0crat in |
@0crat refuse |
@marceloamadeu The user @marceloamadeu/z resigned from #135, please stop working. Reason for job resignation: Order was cancelled |
@marceloamadeu Job refused in 0 hours - no penalty, see §6 |
The architect of the project has changed; @paulodamaso/z is not at this role anymore; @victornoel/z is the architect now |
@0crat in |
@0crat assign @longstone |
@victornoel The job #135 assigned to @longstone/z, here is why; the budget is 30 minutes, see §4; please, read §8 and §9; if the task is not clear, read this and this; there will be no monetary reward for this job |
@victornoel There is an unrecoverable failure on my side. Please, submit it here:
0.53.15: CID: 517db924-424d-4421-9211-a99c20b75a3b, Type: "Order was given" |
@0crat assign me |
@victornoel the puzzle #165 is still not solved. |
@victornoel Job #135 is already on hold |
@victornoel 2 puzzles #224, #225 are still not solved; solved: #165. |
@victornoel the puzzle #224 is still not solved; solved: #165, #225. |
Problem
I believe the two
TextMatcherEnvelope
andMatcherEnvelope
used in cactoos-matchers are a hijacking of the term envelope just to justify using inheritance in a bad way.Now we have many objects whose behaviour is distributed in their own and parent class.
Envelopes
An envelope is an abstract class meant to help decorate object of a certain type, let's call it T, in order to ease applying the decorator pattern in EO around objects of type T.
Usually an envelope only exists to delegate calls to a wrapped object of type T according to the contract (the methods) of T.
From there there should be some base implementations of T that implemented some specific behaviour, and decorators of T can just extend the envelope and use the base implementations to pass it to super.
Here is an example of a proper envelope: https://github.com/yegor256/cactoos/blob/master/src/main/java/org/cactoos/func/FuncEnvelope.java
More details here: http://www.yegor256.com/2017/01/31/decorating-envelopes.html
Note: sometimes in the EO world, envelopes are called wrap (
XXXWrap
).Solution
In cactoos-matchers, there should be only a
MatcherEnvelope
that simply delegates the methods ofMatcher
without imposing any specific behaviour and then:TextMatcher
(not extendingMatcherEnvelope
) that would contain the actual behaviour currently implemented inTextMatcherEnvelope
. To use it,TextIs
for example, would extendMatcherEnvelope
and rely onTextMatcher
to pass to super.MatcherOf
should take the three currently constructor arguments thatMatcherEnvelope
currently propose and implement the methods ofMatcher
with them.Note on
Matcher
libraryOf course because we rely on
Matcher
, an abstraction introduced by a non EO library, some of our matchers (all those that are not defined in terms of other view decoration) will still need toextends TypeSafeDiagnosingMatcher
.The text was updated successfully, but these errors were encountered: