• Post Reply Bookmark Topic Watch Topic
  • New Topic

OO Principles  RSS feed

 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paweł Baczyński
Bartender
Posts: 2074
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, what do you think is the correct answer? Remember to show some effort when asking questions.
Second, this looks like a question from a mock exam, so please quote your sources.
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh yes.. i know the answer now, it's Looser coupling and higher cohesion.
i posted here too soon without trying much.
I tried to delete the topic but couldn't.
 
Paweł Baczyński
Bartender
Posts: 2074
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shubham Semwal wrote:oh yes.. i know the answer now, it's Looser coupling and higher cohesion.

And why do you think those are correct? I would answer differently.
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Baczynski wrote:
Shubham Semwal wrote:oh yes.. i know the answer now, it's Looser coupling and higher cohesion.

And why do you think those are correct? I would answer differently.


It's a bit confusing but i'd go with these two due to the following reasons :

looser coupling : Since they were able to remove some methods without change in any functionality it's safe to assume that either these methods were accessing fields of other classes or their code is now added to remaining methods. [it's a good contender for answer]

higher cohesion : Taking the 2 cases for loose coupling both increase the cohesion of existing class resulting in specialized methods (or the cohesion remains the same but certainly it doesn't lowers.)

Encapsulation : Not enough info for either of the options.
 
Tyson Lindner
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A and D would be my answers as well, but wow, what a vague and terrible question. Merely saying you're "reducing methods without losing functionality" can be applied to a lot of principles. Also having more methods isn't even necessarily a bad thing in itself, sometimes it makes code a lot easier to read.
 
Tyson Lindner
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got my answers more from a process of elimination approach.

A, D, and F are generally considered "good". No one is having a meeting deciding that their classes need tighter coupling and lower cohesion. F, however generally means writing more methods because you're creating more getters and setters. So that just leaves A, and D.
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say that there is a good case to say that 'F' implies less getters and setters, not more. The less ways there are to directly access the contents or state of an object the better encapsulated its functionality will be.

But obviously if the class is using public fields then it has no encapsulation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!