java.lang.Object
io.github.astrapi69.design.pattern.observer.AbstractObserver<T>
Type Parameters:
T - the generic type of the observable object
All Implemented Interfaces:
ActionCommand, Observer<T>

public abstract class AbstractObserver<T> extends Object implements Observer<T>, ActionCommand
A generic implementation of the Observer pattern This abstract class implements the Observer and ActionCommand interfaces, providing a basic framework for observers in the Observer design pattern
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Subject<T,Observer<T>>
    The subject being observed
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for a new observer object
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the current observable object
    void
    update(T observable)
    This method is called to notify the observer of changes in the observable object Implementing classes should define the specific behavior that occurs when the observable object changes

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.github.astrapi69.design.pattern.observer.api.ActionCommand

    execute
  • Field Details

  • Constructor Details

    • AbstractObserver

      public AbstractObserver(Subject<T,Observer<T>> subject)
      Constructor for a new observer object
      Parameters:
      subject - the subject to observe
  • Method Details

    • getObservable

      public T getObservable()
      Gets the current observable object
      Returns:
      the observable object
    • update

      public void update(T observable)
      This method is called to notify the observer of changes in the observable object Implementing classes should define the specific behavior that occurs when the observable object changes
      Specified by:
      update in interface Observer<T>
      Parameters:
      observable - the observable object that has changed