About Question enthuware.ocpjp.v7.2.1177 :

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

Moderator: admin

Post Reply
jklb
Posts: 17
Joined: Tue Dec 18, 2012 7:54 pm
Contact:

About Question enthuware.ocpjp.v7.2.1177 :

Post by jklb »

I used the "Head First Design Patterns" by Freeman, Sierra and Bates to prepare for the exam and in Chapter 9 they introduce single responsibility along with the Composite pattern. For example, the composite pattern helps deal with the problem of needing to deal with two responsibilities: handling aggregation and handling iteration.

I didn't select DAO or Composition, so I was really off-base, but I did some more researching when I was reviewing answers and now believe Composition is the correct answer.

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

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

Post by admin »

I don't know about what other book says but composite pattern actually violates the single responsibility principle. The question asks you to select a pattern that illustrates this principle so composite is not the right answer.

HTH,
Paul

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

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

Post by The_Nick »

Hi everyone,

What about the Factory Pattern?
Isn't that single responsability too? it just creates entities.

Thanks in advance.

The_Nick.

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

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

Post by admin »

Tangentially, yes. That way, even Singleton has only one responsibility i.e. to make sure there is only instance of a class. But I do not think these are appropriate choices because that is not their primary objective. Of course, it can be quite subjective.

HTH,
Paul.

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

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

Post by Student »

According to wikipedia (no sniggering)

"In object-oriented programming, the single responsibility principle states that every class should have a single responsibility, and that responsibility should be entirely encapsulated by the class".

Also (http://www.oodesign.com/single-responsi ... ciple.html):

"This principle states that if we have 2 reasons to change for a class, we have to split the functionality in two classes. Each class will handle only one responsibility and on future if we need to make one change we are going to make it in the class which handle it. When we need to make a change in a class having more responsibilities the change might affect the other functionality of the classes."

Therefore it would appear this is a principle that should be applied to all classes i.e. it's a foundational OO programming principle, and not something that is the province of any particular pattern.
Humbly,
Student

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

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

Post by admin »

Please see the discussion above. As mentioned above, it is quite subjective. So no matter what you believe, there will be contradicting opinions. So our suggestion is to go with the most reasonable answers without trying to split hair because in the exam you will not be given space to write your arguments about why you think an option is correct or incorrect. You have to pick the one that will be evaluated as correct :)

HTH,
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests