TL;DR: The answers are phrased as if AdvancedReporter and SpecialReporter should be left unchanged, but the question explicitly asks about extracting functionality, i.e. some degree of refactoring. The example in the explanation does not take this into acount.
Full analysis of answers:
ReporterFactory: Wrong because we are not extracting functionality as requested. Also wrong because we are not using composition as requested.
On the composition side, one could argues that classes are factories and ReporterFactory composes AdvancedReporter.class and SpecialReporter.class; however, the purpose of the exam is to test the knowledge of standard definitions, not his ability to think outside the box.
CommonReporter with generateTextReport: Correct though the class name is a misnomer, it should be TextReporter. But then we are not asked to find the best design, because in that case we'd be asked about improving the names of AdvancedReporter and SpecialReporter; we are asked to apply a specific kind of refactoring.
CommonReporter with generatePDFReport and generateHTMLReport: Wrong because both AdvancedReporter and SpecialReporter have the features that distinguish them extracted out and are left with just generateTextReport, which is pure nonsense. Also, CommonReporter does not use composition for PDF and HTML generation but contains the code directly.
This answer would be correct if the question didn't talk about extracting functionality. Even then, it would be incomplete because it leaves out how to deal with generateTextReport.
Creating a common superclass fulfils the "extract functionality" requirement. What is not mentioned is that we also need a Reporter class that delegates to either CommonReporter, Reporter, AdvancedReporter, or SpecialReporter. Now one could consider this answer as too incomplete to be the correct one, but then all the other answers are either plain wrong, or incomplete in some other way.
From the PoV of "which answer is least incomplete", answer 2 would be correct.
From the PoV of "which answers describe at least a part of a working solution that involves extraction of functionality", answers 2 and 4 are correct.
Did I miss some point?
About Question enthuware.ocpjp.v7.2.1097 :
Moderator: admin
-
- Posts: 38
- Joined: Fri Nov 13, 2015 4:40 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1097 :
Any option that asks you to "implement" any functionality is wrong because all the functionality is already implemented by the two classes. Therefore, option 2 and 4 cannot be correct.
The question explicitly asks you to "mix and match using composition". This is a dead give away for a facade.
Yes, the reference to "extract" causes a bit of ambiguity. That is the reason for the disclaimer in the question:
"The problem statement is not very clear as to what it expects but some candidates have reported getting similar vague requirement. We have included this question with our best guess for the answer."
It is, finally, up to you to decide which part of the problem statement should be given more importance while selecting the answer.
HTH,
Paul.
The question explicitly asks you to "mix and match using composition". This is a dead give away for a facade.
Yes, the reference to "extract" causes a bit of ambiguity. That is the reason for the disclaimer in the question:
"The problem statement is not very clear as to what it expects but some candidates have reported getting similar vague requirement. We have included this question with our best guess for the answer."
It is, finally, up to you to decide which part of the problem statement should be given more importance while selecting the answer.
HTH,
Paul.
-
- Posts: 38
- Joined: Fri Nov 13, 2015 4:40 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1097 :
Options 2 and 4 talk about creating classes that "contain implementations", which can be correct if the code is extracted. If the options said "implement", then I agree the answers would have been "less correct". (I think we agree that option 4 is wrong for at least one other reason, because it uses inheritance instead of composition.)
"Mix and match" means you can combine any element with something. In this scenario, it would probably mean combining a specific Report() function with some unshown input.
However, you do Facade for that only if you want low coupling. Given the "company" context you can't assume that, and you can't do Facade unless the interfaces are really identical; you'd also need glue code to make up for API differences, which would then indeed mean "implement something" instead of "extract code".
I have seen the disclaimer. However, the question is actually quite precise: How do you extract code in a refactoring situation, and where do you move it.
I'm under the impression that the question wasn't fully understood, and that's why it is being represented as vague.
I'd be interested enough to test that hypothesis, so if if somebody sends me the original question and answers under seal of confidentiality, I will check the wording and send back my interpretation.
"Mix and match" means you can combine any element with something. In this scenario, it would probably mean combining a specific Report() function with some unshown input.
However, you do Facade for that only if you want low coupling. Given the "company" context you can't assume that, and you can't do Facade unless the interfaces are really identical; you'd also need glue code to make up for API differences, which would then indeed mean "implement something" instead of "extract code".
I have seen the disclaimer. However, the question is actually quite precise: How do you extract code in a refactoring situation, and where do you move it.
I'm under the impression that the question wasn't fully understood, and that's why it is being represented as vague.
I'd be interested enough to test that hypothesis, so if if somebody sends me the original question and answers under seal of confidentiality, I will check the wording and send back my interpretation.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1097 :
We do not have the original question exactly as presented in the real exam. So there will be some difference between the real exam question and this question. And that difference may certainly cause a whole lot of difference to the correct answer!
I hope other people see this discussion and report back their observations.
-Paul.
I hope other people see this discussion and report back their observations.
-Paul.
-
- Posts: 38
- Joined: Fri Nov 13, 2015 4:40 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1097 :
That would be good, yes.
Who is online
Users browsing this forum: Google [Bot] and 3 guests