Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSS446 Spring 2014 Nan Wang.  To be able to declare and use interface types  To appreciate how interfaces can be used to decouple classes  To learn.

Similar presentations


Presentation on theme: "CSS446 Spring 2014 Nan Wang.  To be able to declare and use interface types  To appreciate how interfaces can be used to decouple classes  To learn."— Presentation transcript:

1 CSS446 Spring 2014 Nan Wang

2  To be able to declare and use interface types  To appreciate how interfaces can be used to decouple classes  To learn how to implement helper as inner classes 2

3  Upcasting, can convert from a class type to the type of any interface that the class implements (automatically).  Downcasting, interface  classes If the object(max) doesn’t actually refer to a country, a run­time exception will occur. 3

4  Invoking Methods on Interface Variables The Java virtual machine locates the correct method by first looking at the class of the actual object, and then calling the method with the given name in that class. 4

5  A Measurable interface is used to measuring a single object.  The Comparable inter­face compares two objects. Return a negative number if a should come before b, zero if a and b are the same, and a positive number if b should come before a.  Comparable interface 5

6  Once the BankAccount class implements the Comparable interface, can sort bank accounts array with the Arrays.sort method 6

7 7

8 A callback is a mechanism for bundling up a block of code so that it can be invoked at a later time. 8

9  A class that is declared inside another class is called an inner class.  The inner class is available to all methods of the enclosing class. Execute file: outerclassName$innerclassName.exe 9

10  Anonymous object— an object without a name. only used once Using anonymous class if the class is never used again after a single object of it has been constructed. 10

11  Testing some of the classes before the entire program has been completed.  providing the same services as another object, but in a simplified manner. 11  declare an interface type with the same methods that the Grade­ Book class provides.  provide a mock implementation that makes some simplifying assumptions  construct an instance of MockGradeBook and use it in the GradingProgram class which manipulates the mockGradeBook.


Download ppt "CSS446 Spring 2014 Nan Wang.  To be able to declare and use interface types  To appreciate how interfaces can be used to decouple classes  To learn."

Similar presentations


Ads by Google