Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

OTExample Observer/Hummingbird

< OTExample Observer
Revision as of 07:27, 23 February 2010 by Unnamed Poltroon (Talk) (New page: '''Simple base class for the Observer pattern''' (''note, that this class bears no pre-planning for observing''). <source lang="otj"> package flower_example; /** * @author Bruce Eckel (...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Simple base class for the Observer pattern

(note, that this class bears no pre-planning for observing).

package flower_example;
/**
 * @author Bruce Eckel (original Java example)
 * @author Miguel P. Monteiro (adaptation to OT/J)
 *
 * Base class to play the Observer role
 */
public class Hummingbird {
    private String _name;
 
    public Hummingbird(String name) {
        _name = name;
    }
 
    //Reaction to Flower.open
    public void breakfastTime() {
        System.out.println("Hummingbird " + _name + "'s time to have breakfast!");
    }
 
    //Reaction to Flower.close
    public void bedTime() {
        System.out.println("Hummingbird " + _name + " goes to sleep!");
    }
}

Back to the top