Juha Manninen wrote 5 lines
Thanks.
Java shines with its container classes. Iterator interface and support for
generics types are just cool. It all could be implemented with Object Pascal
as well.
Yes, java is great in that way, but it was decided not to extend the classes in the RTL with such functionality. So I implemented them as external classes that gets created by a Factory Method, using a lazyman's Singleton.
It can now be used as follows... Good news is that any iteration code over any list class (object list, string list, tree view) now looks the same. No need to know if the list class is 1-based or 0-based etc.. The container/list class can now change internally, and no iteration code needs to change either.
var
itr: IStringIterator
begin
itr := gIteratorFactory.StringIterator(lst);
if Assigned(itr) then
begin
while itr.HasNext do
Add(itr.Next);
end;
itr := nil;
end;
I think I made some changes to the units included with the article, so I attached the latest ones I have.