I have to implement three different sorting algorithms using an Object-Oriented Approach and I have been thinking of the best method to combat this.
Basically, I think it should look like this:
-> Sort (Class, interface, Polymorphic)
Inherit:
-> Bubble Sort
-> Insertion Sort
-> QuickSort
If each of the sorts have the same interface then it would be easier to access the different methods of sorting, thus, meaning that when I come to add other sorting algorithms, I can easily implement them into the current design and class structure.
My questions are:
-
Is this a good approach to use?
-
Is there scope for me to use Templates? I.e. if I wanted to use Bubble, it would call the bubble sort, if I wanted to use Insertion it would call Insertion?
As suggested use an interface (pure virtual class)
Interface Method:
Now when you want to sort you simple do the following:
Template Method:
This is used as follows: