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.
About Question enthuware.ocpjp.v7.2.1177 :
Moderator: admin
-
- Posts: 17
- Joined: Tue Dec 18, 2012 7:54 pm
- Contact:
-
- Site Admin
- Posts: 10398
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1177 :
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
HTH,
Paul
-
- Posts: 132
- Joined: Thu May 16, 2013 9:23 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1177 :
Hi everyone,
What about the Factory Pattern?
Isn't that single responsability too? it just creates entities.
Thanks in advance.
The_Nick.
What about the Factory Pattern?
Isn't that single responsability too? it just creates entities.
Thanks in advance.
The_Nick.
-
- Site Admin
- Posts: 10398
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1177 :
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.
HTH,
Paul.
-
- Posts: 53
- Joined: Fri Sep 20, 2013 7:20 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1177 :
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
"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
-
- Site Admin
- Posts: 10398
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1177 :
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.

HTH,
Paul.
Who is online
Users browsing this forum: No registered users and 6 guests