Object-oriented programming and algorithmic programming

I haven’t been writing the last two days since I was in Herning for a family birthday but I have been thinking about my Object-oriented programming in R book. Specifically, I have been thinking about algorithmic programming and object-orientation.

Most books I have read on object-oriented programming, and the classes I have taken on object-oriented programming, have centred on object-oriented modelling and software design. There, the focus is on how object-orientation can be used to structure how you think about your software and how the software can reflect physical or conceptual aspects of the world that you try to model in your software. If, for instance, you implement software for dealing with accountance you would model accounts as objects with operations for inserting and withdrawing money. You would try to, as much as possible, mapping concepts from the problem domain to software as directly as possible.

This is a powerful approach to designing your software, but there are always aspects of software that does not readily fit into such modelling. Especially when it comes to algorithmic programming and design of data structures. Search trees and sorting algorithms, for instance, are usually not reflecting anything concrete in a problem domain.

Object-oriented programming, however, is also a very powerful tool to use when designing algorithms and data structures. The way I was taught programming, algorithms and data structures were covered in separate classes from where I was taught object-orientation. Combining object-orientation and algorithmic programming was something I had to teach myself by writing software. I think this was a pity since the two really fit together well.

Polymorphism, a cornerstone of object-oriented programming, lends itself readily to developing flexible algorithms and to combining different concrete implementations of abstract data types to tailor abstract algorithms to concrete problems.

To which degree you would call this object-oriented programming I don’t know. It is more the polymorphism that is important — and polymorphic code is found in many other programming paradigms — but this book seems like as good a place as any to include topics like polymorphic code in designing algorithms and data structures.

When data structures and algorithms a taught in separate classes from, say, functional programming and object-oriented programming, you have to figure out how it all fits together yourself. In actual use, you have to fit it all together.

I don’t know if I am able to write about this in a way that makes the puzzle pieces fit together, but I will at least try to give it a go.