- Factories and the Recurring Need to Copy Objects
- Linked Java Structures
- Running the Supplied Code
Running the Supplied Code
All of the source code described in this article is available as a zip file for download. You can run the supplied CLASS files from the command line, or if you prefer you can compile and build the Java files yourself.
Conclusion
With programming, the devil really is in the details! Top-notch Java developers have a way with the vernacular of the language, using copy constructors and the Copyable interface to good effect when the need arises. These tools allow for creating new copies of objects in a manner similar to the prototype design pattern. Rather than instantiating a whole new base object, the latter can be used to produce a copy for you. This avoids a good deal of overhead, potentially allowing for very efficient factory-style patterns.
Linked data structures are very useful for creating unconstrained collections. You can add, modify, and delete linked list entries with ease and speed. Deletion of linked list entries in Java can make powerful use of the garbage collector. This helps to avoid the difficult problem of memory leakage. So, it can be said that linked structures in Java give you the best of procedural languages in the form of pointers (or links to the next item in the list) as well as easy deletion.
Making good use of the finer details of a programming language is an example of moving up the value chain. You get more bang for your buck, and you get dividends down the line.