Are you suggesting to put the condition directly in the handleData method? Then how would the factory know what instance to return? I do like the Tell-don’t-ask principle, but didn’t get how you’d apply it here.
We might put a if (!shouldHandle(url)) throw ... in the beginning of the handleData method to offer some protection against fools.
As I said I’ve borrowed this pattern from Spring, in an earlier version I had put a piece of their code, perhaps I’ll put it again to illustrate how they use it.
Thanks a lot for your feedback!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Trifon!
Are you suggesting to put the condition directly in the handleData method? Then how would the factory know what instance to return? I do like the Tell-don’t-ask principle, but didn’t get how you’d apply it here.
We might put a if (!shouldHandle(url)) throw ... in the beginning of the handleData method to offer some protection against fools.
As I said I’ve borrowed this pattern from Spring, in an earlier version I had put a piece of their code, perhaps I’ll put it again to illustrate how they use it.
Thanks a lot for your feedback!