Observer<State> class
abstract
Observer Pattern - Observer
The Observer
class is an abstract class that defines the behavior of an observer in the Observer Pattern.
An observer is an object that watches a subject and receives updates when the subject's state changes.
The observer can be attached to or detached from a Subject
.
When there's a change in the state of the subject, the observer is notified through a function called update. This function can then perform some actions with the new state information provided to it by the subject.
Alternative Constructors
It's provided alternative constructors to create an observer.
coupled
- Creates a CallbackCoupledObserver that is notified when is attached or detached from a subjectstream
- Creates a StreamObserver that can be listened tostateful
- Creates a StatefulObserver that holds the last state of the subject
Constructors
-
Observer.new(ObserverCallback<
State> callback) -
factory
-
Observer.coupled({CoupledObserverCallback<
State> ? attached, CoupledObserverCallback<State> ? detached}) -
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
Subject< State> subject, State state) → void -
This method is called whenever there is a change in the state of the
Subject
.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
stateful<
State> () → StatefulObserver< State> -
stream<
State> ({bool sync = true, bool autoDispose = false}) → StreamObserver< State>