>Hi Gregory,
>
>First, thank you for sample code. It does look straight forward. I am not arguing that the collections approach is valid. Aside from my concern for making a mistake in something that I have never used before and breaking an existing application (which I am refactoring), I have the following point. Why is collections (in this particular case of storing a bunch of names) better than array? Array - with the help of an INLCUDE file - can be addressed with "key" names too.
Dmitry,
In this case, it is not better at all. Just a minor detail - if you add/delete something later you'll have to change the dimension of the array
The nice things about a collection are (I may be missing a few)
- you can subclass it, and add functionality
- it grows/shrinks dynamically as items are added/deleted
- you cannot add any property/function to an array
see message#
1404171 for an example of creating a Queue and a Stack class based on collection
In my collection base class I have eg changed the base Add() to return a bool if Add() fails (so try catch needed)
Same with retrieving data from the collection
I can clone() it
Stacks/queues, I can reverse
.....
All written once and scoped to the collection
With an array, I would have a lot of functions scattered around
Also you can test whether a collection is empty, whereas with a (foxpro) array you cannot
I avoid arrays when I can
Gregory