|
I've thought for sometime that ArrayList
was a pretty sweet little class. I know, "It's such a simple portion
of the Java Collections Framework", but I don't think most engineers
appreciate it as they should. There are three incredibly powerful things about
ArrayList, that if every other Class followed would probably make them as
awesome too....
1) First, Ease Of Use. ArrayList
has a pretty simple set of 16
methods that make it's use expand to well beyond everyday program, but not
overwhelm the ceveloper with a massive 'hint dialog' nor with a fear of needing
to understand them all. It has followed a well thought direction of Java
development, that's probably why it's been there since 1.2, keeping
getter/setter, coupling and OO concepts clean. It has no funkyness like Calendar,
which tends to make it's own arguments to pass if the parameters you pass are
in anyway even slightly strange or.... well this is a whole separate entry. All
in all this class is simple enough for a new-to-programming person as well as a
I-know-all-about-advanced-COBOL person.
2) Second, Self Regulating. ArrayList, as part of what makes it the
class that it is, has the uncanny ability to grow and shrink it's own capacity
as Objects are added and removed from it. Although ArrayList is a simple
example of this 'self-aware' aspect it cannot be commended enough. With the
addition of the conains(), indexOf() and remove() methods ArrayList's self
regulating of capacity becomes, in a sense, a self encapsulated attribute. I
wonder if I can say that?
3) Third, Objects Only... Please. Now some people may argue that
ArrayList holding only objects is a limitation, well they are just silly. In
the same way that particular aspects of Java are the way they are to force good
habits, ArrayList is no different. By taking only Objects it nudges a
new-to-programming person towards understanding objects and thinking in OOD
concepts, while it encourages the I-know-all-there-is-about-FoxPro person to
consider more deeply how to make everything an object, within reason of course.
Conclusion. ArrayList is a great example of how classes should be made,
and what considerations should be had while choosing functionality and
usability of your methods. Go You ArrayList, Go You. |