• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Package dependencies

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I'm a little confused on when to use sub packages, and the dependencies that should exist between a package and a sub package.
In Swing and AWT there seems to be quite a few cyclic dependencies between packages and sub packages.
For Example,
JTable exists in the javax.swing package. This class referencies classes( eg DefaultTableCellRenderer) within javax.swing.table.
However the DefaultTableCellRenderer class in packagage javax.swing.table referencies javax.swing.JTable. Hence circular dependency!!
The question is, should packages be dependent on subpackages ? or vice-versa ?... or should we be trying to avoid circular dependencies at all?... or am I getting worried about something that I shouldn't be worried about at all, and probably get out more!
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Martin,
It is impossible to remove all the dependencies completely.We should also not be attempting this as the basic purpose of OO - collaboration would be defeated.At best, we should try to reduce them to the minimum.
Fowler suggests, we should use interfaces to minimize dependencies as much as possible.The class talking to the interface would not know until runtime, which object type the interface is referencing.This solution based on Indirection Pattern would reduce dependency.
Hope this helps,
Sandeep
 
Martin webster
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Desai,
I've reduced the dependencies between the packages. I'm still a little unsure whether a package should be dependent on a sub-package, or the other way round....I guess it doesn't make much difference aslong as the dependency is modeled..
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Martin,
From what I understand, the packages (and its sub-packages) are designed by specialization.Dependencies would exist between the package and someone calling the classes of the package from outside.
However, as far as package and sub-package is concerned, it doesn't signify a dependency.If you have a sub-package, probably you would have created it because the classes in the outer package is associated with its sub-package.This association(not dependency) could be one way or two-way, which has been decided during the design process.
Hope this helps,
Sandeep
 
He's my best friend. Not yours. Mine. You can have this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic