Thursday, November 1, 2007

Example of the Adapter Pattern

The adapter pattern was another pattern that I felt I've seen before, the first thing that came to mind were event listeners. I then searched through the Java 1.5 API and found a class that works as an adapter, WindowAdapter. The point of the adapter pattern is to convert the interface of a class into another interface that the client expects. In the case of WindowAdapter, WindowAdapter would be the adapter with an interface the client expects. Within WindowAdapter, there are various methods such as windowClosed and windowOpened, these are the methods that make calls to the Adaptee. So the client makes a call where the adapter then calls the method of the adaptee. This way you can use an existing class when its interface doesn't match the class that is needed.

1 comment:

Dondi said...

OK, home stretch now --- you haven't posted in more than a month, so let's hope that your final report is substantive. To recap, your final report, which is due at the end of the semester, should include:

- A description of what you studied, and the sources consulted.

- A more detailed account of the items in this blog.

- A detailed account of how you applied what you learned about patterns to the 401 project: the patterns you used, why you used them, plus other design elements in that project which can benefit from further refactoring.

Talk to me if you have any questions.