Type Parameters:
T - the generic type of the observable object whose state is being observed
O - the generic type of the observer that is observing the subject
All Known Implementing Classes:
AbstractSubject, ChatRoom

public interface Subject<T,O extends Observer<T>>
The interface Subject represents the "subject" in the Observer design pattern The subject is the object whose state changes are being observed by one or more observers When the state of the subject changes, the observers are notified of the change
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    add(O observer)
    Adds the given observer to the list of observers
    default void
    addAll(Collection<O> observers)
    Adds the given observers to the list of observers
    Gets the observable object, which is the object being observed for state changes
    Gets the list of observers that wish to be notified of changes to the observable object
    default void
    remove(O observer)
    Removes the given observer from the list of observers
    default void
    removeAll(Collection<O> observers)
    Removes the given observers from the list of observers
    void
    setObservable(T observable)
    Sets the observable object, which is the object being observed for state changes
    default void
    Notifies all observers of a change in the state of the observable object Each observer's update method is called with the current state of the observable
  • Method Details

    • add

      default void add(O observer)
      Adds the given observer to the list of observers
      Parameters:
      observer - the observer to be added
    • addAll

      default void addAll(Collection<O> observers)
      Adds the given observers to the list of observers
      Parameters:
      observers - the observers to be added
    • getObservable

      T getObservable()
      Gets the observable object, which is the object being observed for state changes
      Returns:
      the observable object
    • setObservable

      void setObservable(T observable)
      Sets the observable object, which is the object being observed for state changes
      Parameters:
      observable - the new observable object
    • getObservers

      List<O> getObservers()
      Gets the list of observers that wish to be notified of changes to the observable object
      Returns:
      the list of observers
    • remove

      default void remove(O observer)
      Removes the given observer from the list of observers
      Parameters:
      observer - the observer to be removed
    • removeAll

      default void removeAll(Collection<O> observers)
      Removes the given observers from the list of observers
      Parameters:
      observers - the observers to be removed
    • updateObservers

      default void updateObservers()
      Notifies all observers of a change in the state of the observable object Each observer's update method is called with the current state of the observable