From the course: Java EE: Contexts and Dependency Injection

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

What are events and observers?

What are events and observers?

From the course: Java EE: Contexts and Dependency Injection

Start my 1-month free trial

What are events and observers?

- [Speaker] The CDI API provides a lightweight event and observer feature that implements the observer pattern in a very decoupled way. The idea behind the observer pattern is that an object that changes its state can inform other objects that the change has occurred. Essentially it's about passing messages from one object to another and it's what object or entity languages like Java is all about. Passing messages between objects. But why would you want to do this in the first place? Well the purpose is to communicate state change that provokes some action in another part of the system. Say imagine a stock trading system that continually receives stock price change information. The trading system needs to monitor those price changes and react to them by selling or buying more of that stock. So in this system, the trading bots are waiting patiently to receive notification that a change in price, a change in state, of a stock has occurred. So they can do something with that information.…

Contents