Tuesday, 27 January 2009

The Matrix: revisited

One important class is still missing from the matrix implementation: the enumerator.
An enumerator is in my opinion , a workaround for the fact that the concept of 'BLOCKS' are missing in Objective-C.
If it was possible to use blocks like , for example, in Smalltalk then enumerators would be useless.

In this case I made a subclass of the abstract class NSEnumerator and called it MatrixEnumerator.
The protocol definiton of NSEnumerator obliges us to implement 2 methods ( nextObject and allObjects ).

I've added one more method and that is setTraversalOrder: ; with this method you can specify how the traversal will take place (by row first then by column or by column first then by row).

A new version of the Matrix project (including the enumerator) can be found here
Some extra functionality is also added to the Matrix class, it's now possible to get a row or a column from a matrix. Note that the rows or columns are copies from the original matrix.

No comments:

Post a Comment