This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object Orientation

 
aruna dabas
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


class One {
private int x;
int getX() { return x; }
}

class Two {
private int y;
public void setY(One o) {
y = o.getX();
}
}

Which is true?

These classes are NOT coupled.
These classes are loosely coupled.
These classes are tightly coupled.
These classes are abstractly coupled.


Q:Which is true?

Has-a relationships must be tightly coupled.
Is-a relationships must be well encapsulated.
Is-a relationships can be represented by using reference variables as local variables.
Has-a relationships can be represented by using reference variables as local variables.
Has-a relationships can be represented by using reference variables as instance variables.

Please Explain me the answers as i am confused in this kind of questions.
Thanking You
 
Ruben Soto
Ranch Hand
Posts: 1032
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the first example, I think the classes are loosely coupled. That's because the second class doesn't rely on the implementation of the first class. The programmer/s of the first class can change the implementation of getX() (for example, in order to return a random integer within a range) without breaking the code of the second class.

For the second example:
Has-a relationships must be tightly coupled.
(False, as long as you use the API of the classes for the objects you have.)
Is-a relationships must be well encapsulated.
(False, the question doesn't make any sense.)
Is-a relationships can be represented by using reference variables as local variables.
(False, Is-A is about inheritance.)
Has-a relationships can be represented by using reference variables as local variables.
(False, local variables don't have anything to do with it. Local variables live inside methods.)
Has-a relationships can be represented by using reference variables as instance variables.
(True, if class A Has-A B this means that class A has a reference of type B.)
 
aruna dabas
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ruben.
 
Stephen Davies
Ranch Hand
Posts: 352
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whilst Reuben is right, I think, you should seek more information yourself. The Ranch encourages posters not to answer questions outright but to aid in seeking further information. Giving someone the answer does not truly help to understand an issue outright.

 
Ruben Soto
Ranch Hand
Posts: 1032
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought I was explaining in enough detail the rationale to my answers, and it's not the first time coupling has come up in the forum either. Is there anything else that either Aruna or Stephen (or anyone else in the forum for that matter) would like to discuss about it? Also, how do you think I could have phrased my answers better?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic