user617597
user617597

Reputation: 786

scjp question regarding design

A team of programmers is reviewing a proposed API for a new utility class. After some discussion, they realize that they can reduce the number of methods in the API without losing any functionality. If they implement the new design, which two OO principles will they be promoting?

A. Looser coupling
B. Tighter coupling
C. Lower cohesion
D. Higher cohesion
E. Weaker encapsulation
F. Stronger encapsulation

Can somebody tell me what is the answer?

Upvotes: 2

Views: 5082

Answers (2)

GuruKulki
GuruKulki

Reputation: 26418

My answer will be

Looser coupling and Higher cohesion

If the next question is why? then I would suggest you to go through this article :

http://blog.sanaulla.info/2008/06/26/cohesion-and-coupling-two-oo-design-principles/

Upvotes: 3

Robin Green
Robin Green

Reputation: 33063

I would say, firstly, stronger encapsulation. Suppose one of the methods that is no longer in the API (i.e. it's been made private, or deleted) provides more "low-level" functionality that can still be accessed via the remaining "higher-level" methods. I think that's what you're supposed to assume. In that case, you have improved encapsulation because you can freely change the number and type of arguments to the method, the name of the method, and its return type, or even delete the method entirely and fold its functionality into its caller(s), without affecting clients of the API.

Oh sorry, which two? OK, it will also promote looser coupling, because there are fewer points of coupling between the class and its clients, and thus fewer opportunities to break things in different ways.

Upvotes: 1

Related Questions