• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

tight versus loose coupling

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
UGH, another ambiguous question..this is from a mock exam

Given:

21. class Wheels {
22. private Bike bike;
23. void setBike(Bike b) { bike = b; }
24. }
25.
26. class Bike {
27. private Wheels [] wheels = new Wheels[5];
28. void setWheels(Wheels [] w) {
29. if( w.length == 2)
30. wheels = w;
31. }
32. }

Which is true?
A. Compilation fails.
B. These classes are NOT coupled.
C. These classes are loosely coupled.
D. These classes are tightly coupled.
E. These classes are abstractly coupled.



(Option D is correct because both classes have references to instances of each other.)

Why is this considered tight coupling? Internal changes to either Wheels or Bike classes do not affect the other class. What would make these considered as being loosely coupled?
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rachel Glenn wrote:UGH, another ambiguous question..this is from a mock exam

Given:

21. class Wheels {
22. private Bike bike;
23. void setBike(Bike b) { bike = b; }
24. }
25.
26. class Bike {
27. private Wheels [] wheels = new Wheels[5];
28. void setWheels(Wheels [] w) {
29. if( w.length == 2)
30. wheels = w;
31. }
32. }

Which is true?
A. Compilation fails.
B. These classes are NOT coupled.
C. These classes are loosely coupled.
D. These classes are tightly coupled.
E. These classes are abstractly coupled.



(Option D is correct because both classes have references to instances of each other.)

Why is this considered tight coupling? Internal changes to either Wheels or Bike classes do not affect the other class. What would make these considered as being loosely coupled?



Internal changes to either Wheels or Bike classes will affect the other class, setBike is in Wheels class and setWheels is in Bike class.
 
Rachel Glenn
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Zhenyi Luo wrote:

Rachel Glenn wrote:UGH, another ambiguous question..this is from a mock exam

Given:

21. class Wheels {
22. private Bike bike;
23. void setBike(Bike b) { bike = b; }
24. }
25.
26. class Bike {
27. private Wheels [] wheels = new Wheels[5];
28. void setWheels(Wheels [] w) {
29. if( w.length == 2)
30. wheels = w;
31. }
32. }

Which is true?
A. Compilation fails.
B. These classes are NOT coupled.
C. These classes are loosely coupled.
D. These classes are tightly coupled.
E. These classes are abstractly coupled.



(Option D is correct because both classes have references to instances of each other.)

Why is this considered tight coupling? Internal changes to either Wheels or Bike classes do not affect the other class. What would make these considered as being loosely coupled?



Internal changes to either Wheels or Bike classes will affect the other class, setBike is in Wheels class and setWheels is in Bike class.



Thank you for your reply, but I am still unclear.

Lets look at the class Wheel. It has a member variable; Bike bike. But that is it. It only has a reference to this class. It doesn't call any of Bike's member functions or access any of Bikes' variables. To me, this is a simple has-a relationship. If the internal structure of Bike changes, Wheels is not affected at all. So how is this specific relationship 'tight coupling'?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic