About Question enthuware.ocpjp.v7.2.2002 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Student
Posts: 53
Joined: Fri Sep 20, 2013 7:20 am
Contact:

About Question enthuware.ocpjp.v7.2.2002 :

Post 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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

Student
Posts: 53
Joined: Fri Sep 20, 2013 7:20 am
Contact:

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

Post by Student »

Ok Paul, understood; thanks very much.

ewebxml
Posts: 77
Joined: Sun Jun 30, 2013 10:04 pm
Contact:

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

Post 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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

pbonito
Posts: 13
Joined: Sat May 16, 2015 12:38 pm
Contact:

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

Post 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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

pbonito
Posts: 13
Joined: Sat May 16, 2015 12:38 pm
Contact:

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

Post 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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests