Use nested classes

If two classes are associated with each other in some functional way (such as containers and iterators), try to make one an inner class of the other. This type of nesting of one class within another not only emphasizes the association between the classes, but it allows the class name to be reused within a single package. The Java containers library does this by defining an inner "Iterator" class inside each container class, thereby providing the containers with a common interface.


Bruce Eckel is a frequent author and lecturer on software development practices and was a founding member of the ANSI/ISO C++ committee. The information contained in this article is excerpted from his latest book, "Thinking in Java: Second Edition" (Prentice Hall, 2000). Reach him at Bruce@EckelObjects.com.



Previous: #9 - Don't overuse finalization
 
Back to Introduction


Follow the Sun coding conventions Use "get," "set," and "is"
Standardize! Make iterative testing of classes easy
Follow standard capitalization rules Avoid inheritance
Don't create your own "decorated" private data member names Don't overuse finalization
Follow a canonical form Use nested classes


Java Zone - Get Help - Search Tips
 

Eckel's Ten Java Maxims for Good Design
DevX's Review of Eckel's "Thinking in Java"
"Thinking in Java, Second Edition" DevX product listing
Eckel's Home Page
Java Code Library
Java Pro Magazine
Java Discussion Group

 TALK BACK
Is a set of standard coding rules enforceable in a medium or large organization? Does your team and/or company have a standardized Java coding scheme? Join the discussion and tell our growing Java development community about it.
Click here to Join


Save on Hot Java Specials
SOFTWARE:
dtSearch Web
Add power searching to your web site.
Buy Now!
BOOKS:
PointBase Mobile Edition
Enable local data access for mobile users.
Buy Now!
Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map
Jupiterweb networks

internet.comearthweb.comDevx.comClickZ

Search Jupiterweb:

Jupitermedia Corporation has four divisions:
JupiterWeb, JupiterResearch, JupiterEvents, and JupiterImages

Copyright 2004 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Jupitermedia Corporate Info | Newsletters | Tech Jobs | E-mail Offers