I recently referred to the Mastering Algorithms book,
and as a result used the
Graph module.
When I started, it seemed that I needed to write
a lot of difficult code, and I dreaded the bugs.
Instead, my OO graph representation using this module
solved the whole problem in about 10 lines of code.
No bugs found so far!
I think the graph module shows an example where the
algorithms are naturally object-oriented.
They match at least these three hints paraphrased from
Damian Conway's ten rules for when to use OO:
- Data is aggregated into obvious structures.
- Data forms a natural inheritance hierarchy.
- Many different operations are applied to one
piece of data.
Other good examples for OO would be matrix
and graphics algorithms.
It should work perfectly the first time! - toma