Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

What are the examples of Observer design pattern in JDK?

Pragya Keshap answered on February 10, 2023 Popularity 4/10 Helpfulness 1/10

Contents


More Related Answers

  • What design pattern allows behavior to be added to an individual object
  • Java Observer pattern
  • The Observer pattern – advantages and disadvantages
  • observer pattern java
  • observer pattern java
  • observer pattern
  • observer design pattern
  • What Is the Observer Pattern?
  • java observable to observer
  • What are the design patterns involved in JDBC architecture?
  • Implementation With Observer
  • What is key advantage of observer pattern
  • observer design pattern
  • What is Observer design pattern
  • What are the examples of Visitor design pattern in JDK?
  • What are the examples of Adapter design pattern in JDK
  • Observer pattern usage example
  • Design Pattern:Observability
  • Observer Pattern
  • Observer pattern
  • observer pattern design pattern

  • What are the examples of Observer design pattern in JDK?

    0

    In JDK there are many places where Observer design pattern is

    used. Some of these are as follows:

    1. java.util.Observer, java.util.Observable

    2. javax.servlet.http.HttpSessionAttributeListener

    3. javax.servlet.http.HttpSessionBindingListener

    4. All implementations of java.util.EventListener, and also in

    Swing packages

    5. javax.faces.event.PhaseListener

    https://howtodoinjava.com/design-patterns/behavioral/observer-design-pattern/#:~:text=A%20real%20world%20example%20of,at%20any%20point%20of%20time.

    Popularity 4/10 Helpfulness 1/10 Language java
    Source: Grepper
    Tags: java
    Link to this answer
    Share Copy Link
    Contributed on Feb 10 2023
    Pragya Keshap
    0 Answers  Avg Quality 2/10

    Closely Related Answers



    0

    The Observer pattern is a behavioral design pattern that defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

    In Java, the Observer pattern is implemented using the built-in interfaces Observer and Observable. The Observable class represents the object being observed, while the Observer interface represents the objects that are observing the Observable.

    To use the Observer pattern, you first define an Observable object and its corresponding Observer objects. The Observable object maintains a list of its observers, and when its state changes, it calls the notifyObservers() method to notify all its observers of the change. The Observer objects implement the update() method, which is called by the Observable object to update the observer with the new state.

    For example, suppose you have a Stock class that represents a stock in a stock market. You could define an Observable subclass called StockMarket that maintains a list of Stock objects and notifies its observers when the prices of these stocks change.

    You could then define an Observer interface called StockObserver that defines the update() method, which is called by the StockMarket object to update the observer with the new stock prices. Finally, you could define a Trader class that implements the StockObserver interface and receives notifications from the StockMarket object when the prices of the stocks it is interested in change.

    Popularity 8/10 Helpfulness 2/10 Language java
    Source: Grepper
    Tags: java
    Link to this answer
    Share Copy Link
    Contributed on May 13 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.