AS3 Iterator API Update

I have updated the Iterator API to include a generic CollectionIterator which can be used to iterate over concrete IList implementations such as ListCollectionView, ArrayCollection and XMLListCollection.

I have also removed the abstract base implementation for all concrete Iterators in favor of the IIterator interface.

In case you are not familiar with the Iterator API, it allows developers to traverse an aggregate without the need to expose it’s underlying implementation. Developers can utilize the Iterator API to easily and intuitively iterate over Arrays, Collections and objects with the same Iterator instance. You can also implement the IIterator interface to provide additional concrete iterators in addition to the ones which I have provided; Array Iterator, Object Iterator and Collection Iterator.

A concrete Iterator can be instantiated directly or dynamically at runtime via the IteratorFactory. Typically, developers would type an iterator instance as an IIterator so as to utilize the IteratorFactory to retrieve the concrete iterator types as needed.

I have provided a simple example which contains the compiled source as well as the ASDoc and UML diagram.

source / example
ASDoc
UML

{ 8 comments to read ... please submit one more! }

  1. Bjorn Schultheiss

    Hey Eric,

    Thanks for the update.

    Any chance on getting the source to the swc?

  2. Bjorn Schultheiss

    Hey Eric,

    I’ve recieved errors after the update and using applying COLLECTION_ITERATOR.
    Get back to me and i’ll help debug with a use case.

    Bjorn

  3. I will add the source to the codebase repository within the next day or so. I have posted the IIterator interface in addition to the new CollectionIterator which is available.

    Are you receiving a RTE or compiler error when using COLLECTION_ITERATOR? Send me the code that is failing and I will debug.

    Thanks,
    Eric

  4. Bjorn Schultheiss

    Thanks for the addition to the codebase.

    I’m sorry for the previous post.
    Its seems i too hastly blamed your code for my own code problem.

    Again sorry for posting this on your blog.

  5. Hey Bjorn,

    The included Flex project demonstrates a basic usage example for correctly implementing the API and functions as expected. If you are using the API as prescribed via the example then you shouldn’t have any problems. Send me the exact code which is causing the error and I will debug for you.

    The Iterator API is a basic Iterator Pattern implementation for AS3. Developers familiar with this design pattern and the Factory Pattern shouldn’t have any problems implementing it in their code.

    Thanks,
    Eric

  6. No problem Bjorn, enjoy the API.

    Thanks,
    Eric

  7. why do you need another iterator implementation when ArrayCollection already has IViewCursor?

  8. Thanks for your hard work! I started developing my own IIterator and reading around about different ideas for has to think of the “next.” Lott and Patterson explained a fascinating concept in their book that differed from what I’ve read online in many places until I came to yours.

{ 0 Pingbacks/Trackbacks }