Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

OTExample Observer/Bee

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 Bee {
    private String _name;
 
    public Bee(String name) {
        _name = name;
    }
    /** Reaction to Flower.open */
    public void haveBreakfast() {
        System.out.println("Bee " + _name + "'s breakfast time!");
    }
    /** Reaction to Flower.close */
    public void goToBed() {
        System.out.println("Bee " + _name + "'s bed time!");
    }
}

Copyright © Eclipse Foundation, Inc. All Rights Reserved.