Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Classes with No Coupling?

 
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
 
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.
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • 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.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • 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.
 
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.
    Bookmark Topic Watch Topic
  • New Topic