Reading about the iterator pattern sparked a few thoughts. The Iterator pattern is used in conjuction with Collections. It abstracts the traversal methods out of the Collection. This has the advantage that the code of the relevant collection is not congested with the logic of traversing the list. In addition the responsibility of traversing the collection is offloaded to a separate class. Collection have a factory method called getIterator that provides the Iterator implementation for the collection.
Decoupling the Iterator also provides an additional advantage of being able to apply a wider variety of iteration techniques like Filtered Iterator etc.
Now extending this thought process a bit we can use this decoupling technique to provide Pagination techniques for instance for a list where the paging logic is abstracted from the list itself and handles the paging requests. This can be combined with a session cache so that the paging request does not go down to the db server.
This general approach can potentially be used to declutter a class from responsibilities that do not form it's primary objective.
Decoupling the Iterator also provides an additional advantage of being able to apply a wider variety of iteration techniques like Filtered Iterator etc.
Now extending this thought process a bit we can use this decoupling technique to provide Pagination techniques for instance for a list where the paging logic is abstracted from the list itself and handles the paging requests. This can be combined with a session cache so that the paging request does not go down to the db server.
This general approach can potentially be used to declutter a class from responsibilities that do not form it's primary objective.
No comments:
Post a Comment