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!
Martin
Desai Sandeep
Ranch Hand
Joined: Apr 02, 2001
Posts: 1157
posted
0
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
<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>
Martin webster
Greenhorn
Joined: Jun 20, 2001
Posts: 20
posted
0
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
Joined: Apr 02, 2001
Posts: 1157
posted
0
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