About Question enthuware.ocpjp.v7.2.2002 :
Moderator: admin
-
- Posts: 53
- Joined: Fri Sep 20, 2013 7:20 am
- Contact:
About Question enthuware.ocpjp.v7.2.2002 :
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.
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.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.2002 :
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.

BTW, DAO is to access data, not really for abstracting out physical devices.
HTH,
Paul.
-
- Posts: 53
- Joined: Fri Sep 20, 2013 7:20 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.2002 :
Ok Paul, understood; thanks very much.
-
- Posts: 77
- Joined: Sun Jun 30, 2013 10:04 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.2002 :
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.
"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.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.2002 :
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.
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.
-
- Posts: 13
- Joined: Sat May 16, 2015 12:38 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.2002 :
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.
The question says ... Several application components within your application will need to access this class ... , so it should be better to use an interface.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.2002 :
Why? Just because a class is used by multiple other classes does not imply that you need to use an interface.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.
-
- Posts: 13
- Joined: Sat May 16, 2015 12:38 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.2002 :
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.
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.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.2002 :
Yes, a real world application is a lot bigger. The exam poses only simple problems and looks for a solution for just that problem.
Who is online
Users browsing this forum: No registered users and 10 guests