Forums Register Login

Classes with No Coupling?

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1245 times.
Similar Threads
Low Cohesion or Tight Coupling?
inner classes and encapsulation
Coupling
Coupling and Cohesion
Low coupling??
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 19:12:02.