Using valueobjects might be overkill for some really simple things that only require a couple of values where you can just throw an object together quickly. Unless speed is an issue where they strongly typed values have a lower overhead than plain objects (as I understand it). Unless you’re in a big app and you just made a change to some code and suddenly all your other uses of that object break and you’re not aware of it and null exceptions start flying and…. I digress. Having them in a set collection is great, too, for similar same reasons, plus the added ability to create convenience functions specific to that particular data set. But this post says it all very well with code to boot.
A while ago I blogged about converting Collection and Iterator classes to AS3 since storing data in ValueObjects has become a regular practice in my coding. I really like how VOs are strongly typed and how you use a Collection to hold all the data together nicely. I am working on a project right now that allowed me to see even better uses for these things so I added a couple of simple (but helpful) methods to my Collection class (most notably the ability to add an item at a specified index as well as output the data currently existing in the collection easily) and created a base ValueObject class that allows you to easily output the data in that VO.
Important to also note is the package move. I’ve moved everything into a com.reintroducing.data package as I believe this fits better with what these classes are actually doing. There is also interfaces for ValueObject and Collection as well.
Just so you don’t have to flip back and forth between posts, I’ll post the classes and data here with a little explanation of each.