Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 280 Data Structures Professor John Peterson. Netbeans Magic What you did on Project 2 can be done much more easily if you use the refactoring menu.

Similar presentations


Presentation on theme: "CS 280 Data Structures Professor John Peterson. Netbeans Magic What you did on Project 2 can be done much more easily if you use the refactoring menu."— Presentation transcript:

1 CS 280 Data Structures Professor John Peterson

2 Netbeans Magic What you did on Project 2 can be done much more easily if you use the refactoring menu on NetBeans. 1)Rename “Sortable” to “SortableArrayInt” or something like that. This is done by rightclicking the class name and going to refactor -> rename. When you see the preview of the changes, uncheck the edit on the argument to the sort in main. 2)Right click on the definition of SortableArrayInt and go to refector, then select “extract interface”. Name the extracted interface “Sortable”. Accept all changes.

3 Abstractions When we have general classes of objects that all do something similar, we want to use different sorts of objects interchangeably. The main way of doing this with Java is an interface. This allows us to choose any class that implements the interface when we need a value denoted by the interface. Review: how do interfaces work?

4 Some Abstractions Sorter: something that knows how to sort Sortable: something that can be sorted with an exchange-based sorted Container: an array-like object with a size, a set, and a get. Comparer: something that tells us which object is bigger. Each of these abstractions implies a vocabulary. We will (generally) extend this vocabulary to include “name tags” (descriptions) so we can see who’s who.

5 Sorter What does a sorter do?

6 Sorter public interface Sorter { public void sort(Sortable s); public String description(); } We could put the description in the “toString” too.

7 Sortable We’ve already done this one in the last project. I’d like to add one more method: String description(). This will allow us to debug a little more effectively.

8 Sortable public interface Sortable { public int size(); public boolean gtr(int i, int j); public void swap(int i, int j); public void report(); public String description(); }

9 Container What does our container have to do?

10 Container To make a good container, we need to use generic types so that we’ll know what’s inside. How do generic classes work???

11 Indexable What methods are needed in Indexable?

12 Indexable public interface Indexable { public int size(); public T get(int i); public void put(int i, T obj); }

13 Comparisons We don’t know how to compare general types – the user needs to tell us. How do we do that? An interface which carries a comparison function. As with the container, we need generics.

14 Comparable public interface Comparable { public boolean gtr(T x, T y); }

15 Project #3 This one will be a bit harder! Start early! Ask questions! Get help! Let’s Look:


Download ppt "CS 280 Data Structures Professor John Peterson. Netbeans Magic What you did on Project 2 can be done much more easily if you use the refactoring menu."

Similar presentations


Ads by Google