Tuesday, November 22, 2011
Graph Factories
A thread to discuss the question raised in class today, about using the "factory pattern" to produce graphs.
Monday, November 21, 2011
Programming Assignment #2
See the Assignments section of the main website for the assignment details and the provided source files.
Use the comments section here for questions and discussion.
Use the comments section here for questions and discussion.
Saturday, November 19, 2011
Wednesday, November 9, 2011
Towards a more disciplined Java
Here's something I'd really like. Does anyone know if it exists already? Any other thoughts are also welcome.
A nice feature of Java is its extensive class library. But lots of these classes have been written with a "kitchen sink" mentality--throw in every feature anyone might want. Often, when wants a simple class or interface, such as a FIFO queue, one ends up using something like LinkedList instead, which has a ton of additional functionality. If one is tempted into actually using it, it makes one'd code less portable and harder to maintain.
One way around this is to define a wrapper, or gatekeeper, class FIFOQueue that holds a LinkedList object in a field, and restricts access to all but a handful of its methods. Then the compiler will force you to actually use the right subset of methods. And you can even rename them to your preferred nomenclature. But, there seem to be a number of disadvantages to this approach.
Any suggestions for a better solution? Ideally, I'd like to be able to define a "restricted version" of a class like LinkedList by basically just listing the methods I want to forbid, allow, or rename, and have the compiler or annotations preprocessor enforce the usage restrictions I want. Whether it actually compiles a separate class or not would be a secondary consideration.
A nice feature of Java is its extensive class library. But lots of these classes have been written with a "kitchen sink" mentality--throw in every feature anyone might want. Often, when wants a simple class or interface, such as a FIFO queue, one ends up using something like LinkedList instead, which has a ton of additional functionality. If one is tempted into actually using it, it makes one'd code less portable and harder to maintain.
One way around this is to define a wrapper, or gatekeeper, class FIFOQueue that holds a LinkedList object in a field, and restricts access to all but a handful of its methods. Then the compiler will force you to actually use the right subset of methods. And you can even rename them to your preferred nomenclature. But, there seem to be a number of disadvantages to this approach.
Any suggestions for a better solution? Ideally, I'd like to be able to define a "restricted version" of a class like LinkedList by basically just listing the methods I want to forbid, allow, or rename, and have the compiler or annotations preprocessor enforce the usage restrictions I want. Whether it actually compiles a separate class or not would be a secondary consideration.
Subscribe to:
Comments (Atom)