CSC 216 F09/Interfaces1
Interfaces-Comparing Similarities Among Different Types of Objects by Dan Goslen, Adam Shelton, Byrce Leonard
In this exercise we will be exploring how interfaces can be used to compare different elements among different classes that have similarities. Here is a brief introduction to what interfaces can be used for. Interfaces are also used for has-a relationships you can read more about them in the articles below.
http://cnx.org/content/m11709/latest/ http://msdn.microsoft.com/en-us/library/3b5b8ezk(VS.80).aspx
Before you begin the exercise, make sure to read the article above and to watch this video.
http://www.youtube.com/watch?v=uMInQ7ePH1w
Step one.
Have students list off generic Items.(Example: instruments, clothing, household appliances ) Pick one of these to be used for the rest of the excercise
Step two
Have students list at least three sub items of the previous generic item. (Example: if you chose Clothing then hat, shirt ,pants, and socks would all be appropriate )
Step three
Have three students come up to the board and write as many methods for the interface within 2-3 minutes. Again using Clothing as an example
getPantLength(); getSleeveLength(); getBrandName(); getPrice();
Step Four
Have students create an interface based of the similar off of methods for example all of the articles of clothing would have a getPrice(); method or a getBrand(); Have students discuss what should be in the interface explain why or why not they should be in the interface.