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/Flower

< OTExample Observer
Revision as of 07:29, 23 February 2010 by Stephan.cs.tu-berlin.de (Talk | contribs) (New page: '''Simple base class for the Observer pattern''' (''note, that this class bears no pre-planning for being observed''). <source lang="otj"> package flower_example; /** * @author Bruce E...)

(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 being observed).

package flower_example;
 
/**
 * @author Bruce Eckel (original Java example)
 * @author Miguel P. Monteiro (adaptation to OT/J)
 *
 * Base class to play the Subject role
 */
public class Flower {
    private boolean isOpen;
 
    public Flower() {
        isOpen = false;
    }
    /** Opens its petals. */
    public void open() {
        isOpen = true;
        print();
    }
    /** Closes its petals. */
    public void close() {
        isOpen = false;
        print();
    }
    void print() {
        System.out.println("=> The flower is now "+(this.isOpen?"open":"closed")+".");
    }
}

Back to the top