• Post Reply Bookmark Topic Watch Topic
  • New Topic

Classes with No Coupling?  RSS feed

 
Brian Batson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reading a book preparing for the SCJP exam and it mentions that a programmer should strive for loose coupling but in practice classes will have some degree of coupling to actually be a functioning program. This makes sense. However, the chapter is cryptically concluded by the statement that "Of course, some classes, such as String and Math, are stand-alone classes and have no coupling to other classes." This makes no sense to me. If I use these classes in my class, aren't they coupled to that class? Does anyone have any thoughts on this?

Thanks,
Brian
 
Pramod Kankure
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These classes are loosely coupled meaning you are sending messages between your class and these classes like String so they work together. There is nothing like zero coupling.... At least classes are coupled using messaging.
 
Brian Batson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I thought, too, but the book suggests otherwise. I'm not sure what a "stand-alone" class really is or how it would be useful.
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would see stand alone this way- String and Math classes operation doesnt depend on the state of other objects, they act on the data they have and produce the result.
 
Randall Twede
Ranch Hand
Posts: 4696
8
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe a class like this one? it doesn't depend on any other class once it is created, and i certainly found it useful.
i probably missed the point but oh well.
 
Chetan Sarnad
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Coupling basically comes in to picture if two classes are related to each other. That is if they have a relationship by either "inheritence" or "composition". If a class extends another class, any changes made to the super class will impact the behaviour of the subclass. This means that the classes are tightly coupled. Interfaces should be preferred over the abstract classes for the same reason, i.e interfaces provides loose coupling, where as the classes are tightly coupled if inherited.
String class is an immutable and a final class, it cannot be inherited, hence there is no coupling.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!