Page 1 of 1

About Question enthuware.ocpjp.v7.2.2002 :

Posted: Fri Sep 20, 2013 7:23 am
by Student
Q:You are developing a class that interacts with the bar code reader attached to a machine. Several application components within your application will need to access this class. Which pattern is most suitable in this situation?
A: Singleton. Since there is only one bar code reader attached to the machine, it makes sense to have only one instance of your class that interacts with it throughout your application. Therefore, singleton is most suitable pattern to be used here.
Instead of a bar code reason, you could have a Printer and the same logic will apply.


What if there are many different types of bar code reader? Wouldn't it be a consideration to use the DAO pattern to isolate your logic from your bar coder?

Thanks.

Re: About Question enthuware.ocpjp.v7.2.2002 :

Posted: Fri Sep 20, 2013 7:34 am
by admin
A real life application is not composed of just pattern. So, yes, as the system gets more and more complicated, multiple patterns can be used. In this simple case (and in exam questions), however, you don't need to overthink too much :)

BTW, DAO is to access data, not really for abstracting out physical devices.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v7.2.2002 :

Posted: Fri Sep 20, 2013 8:21 am
by Student
Ok Paul, understood; thanks very much.

Re: About Question enthuware.ocpjp.v7.2.2002 :

Posted: Sat Aug 29, 2015 2:12 am
by ewebxml
For the problem statement, would it be better if it was made clear that,
"There exists 1 bar code reader."

For my own clarification, can you explain which words in the problem statement
would indicate to the reader that the answer could not be the
"Factory" pattern?

Thanks.

Re: About Question enthuware.ocpjp.v7.2.2002 :

Posted: Sat Aug 29, 2015 2:53 am
by admin
1. The problem statement says "...with the bar code reader...". This signifies that there is exactly one device.
2. None of the words in the problem statement indicate Factory pattern. One can certainly use it but the problem statement doesn't indicate it.
3. Finally, such questions are a bit subjective. You can find fault with any option you mark correct. Our objective is to convey what can be expected in the exam and which option should you select in similar cases so that you will get the credit.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v7.2.2002 :

Posted: Tue Oct 06, 2015 11:21 am
by pbonito
You stated: None of the words in the problem statement indicate Factory pattern.

The question says ... Several application components within your application will need to access this class ... , so it should be better to use an interface.

Re: About Question enthuware.ocpjp.v7.2.2002 :

Posted: Tue Oct 06, 2015 11:40 am
by admin
pbonito wrote:You stated: None of the words in the problem statement indicate Factory pattern.

The question says ... Several application components within your application will need to access this class ... , so it should be better to use an interface.
Why? Just because a class is used by multiple other classes does not imply that you need to use an interface.

Re: About Question enthuware.ocpjp.v7.2.2002 :

Posted: Wed Oct 07, 2015 6:38 am
by pbonito
Maybe it's better to not think so much on this questions, but I thought what will happen If the bar code reader machine will change and we'll have to integrate our app with a different code reader?
Meanwhile I don't understand why "Since there is only one bar code reader attached to the machine, it makes sense to have only one instance of your class". You have also one disk on a pc but you don't have just one FileReader.

Re: About Question enthuware.ocpjp.v7.2.2002 :

Posted: Wed Oct 07, 2015 6:56 am
by admin
Yes, a real world application is a lot bigger. The exam poses only simple problems and looks for a solution for just that problem.