# Intro to Interfaces

1. Different sorting algorithms:

• Insertion sort
• Bubble sort
• Quick sort
• Heap sort

2. Bubble sort on integers:

 Bubble sort algorithm for an integer array: ``` input: A = array of integers N = number of elements in A arrayIsSorted = false; while ( ! arrayIsSorted ) { arrayIsSorted = true; for (i = 0; i < N-1; i++) { if ( A[i] & A[i+1] are out of place ) { swap A[i] & A[i+1] arrayIsSorted = false; } } } ```

3. Bubble sort on Strings:

 Bubble sort algorithm for a String array: ``` input: A = array of String N = number of elements in A arrayIsSorted = false; while ( ! arrayIsSorted ) { arrayIsSorted = true; for (i = 0; i < N-1; i++) { if ( A[i] & A[i+1] are out of place ) { swap A[i] & A[i+1] arrayIsSorted = false; } } } ```

4. Conclusion:

• The Sorting Algorithm does NOT depend of the type of objects being sorted.

• And yet.... we have to REWRITE some part of the sorting algorithm to accommodate for the type of objects being sorted.

5. \$6,000,000 Question:

• The IDEAL way to re-use software would be when we DO NOT make ANY changes (in other words: NO changes at all, ZERO, Zippo, NADA, do not even TOUCH the source code of Sort program....) to the Sorting Algorithm itself

• Can we achieve this ideal ?

• Answer: YES. Through an "interface"
That's the strength of Object Oriented Programming