Software Design and Development :: CS 246

08 Prove

Observer Pattern

Objectives

Introduction

The Observer pattern is a very, very common Behavioral pattern. At an abstract level, you can think of your click handlers in Android and other event-driven code as using the Observer pattern.

The purpose of the observer pattern is to allow a class to be notified when certain properties in another class change, or when certain event occur.

Unlike other design patterns, Java actually has some built-in classes to help with the Observer pattern, but you don't have to use those classes to use the Observer pattern.

Assignment

  1. Read this overview of the Observer pattern.

  2. Take a look at the example of how to use Java's built-in Observer and Observable code.

  3. Read this StackOverflow post, which gives more details about Observer and Observable.

  4. Read this StackOverflow post, which explains why Observable is a class but Observer is an interface, and what you should do about it.

  5. Optionally, you might be interested to know how the Observer pattern is often used in iOS and Mac programming, through the Key-Value Observing system and NSNotificationCenter.

    Also optionally, you might be interested to see how the Observer pattern is often used in Windows programming.

Make sure to complete the accompanying quiz for this assignment on I-Learn.