20-CS-694 Advanced Programming Techniques Spring 2012

Interfaces, Exceptions, Graphics, Animation, Threads, Reflection, Networking, RMI, JDBC, JNI

All lectures
Multiple Inheritance

    1.   RealMultiple.java

    Java does not provide for multiple inheritance. However, the same effect can be achieved by creating instances of classes that are needed to provide services and invoking methods from those instances. In case such an instance requires a callback, an interface is used to guarantee that a procedure to catch that callback exists. This shows a typical application of this idea: services are provided by a JButton with a callback to actionPerformed that is guaranteed by interface ActionListener.
    2.   FakeMultiple.java

    This applet attempts to show how java achieves the above. A SomeServiceListener interface is defined. This interface mimicks ActionListener above and requires implementing the method performService which mimicks actionPerformed above. A class called AServicer is defined mimick the Applet class above but provides a different service: simply return a unique number through a service method (which is unused in this example). A class SomeServiceProvider is defined to return a number to an object that is passed into the constructor. That object must be of type SomeServiceListener to guarantee that the number is returned to method performService of that object. The SomeServiceProvider class mimicks the function of the JButton class above. It contains the addSomeListener method which functions like addActionListener for the JButton class. The callback to performService is through a SomeEvent object. The SomeEvent class mimicks the function of the ActionEvent class above. The identity of the SomeServiceProvider object that is invoking performService is included in a SomeEvent object. This enables evt.getSource() to be used in performService as is done in actionPerformed above.