From the course: Java Design Patterns: Behavioral Part 2

Unlock the full course today

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

Implementing an observable

Implementing an observable - Java Tutorial

From the course: Java Design Patterns: Behavioral Part 2

Start my 1-month free trial

Implementing an observable

- [Instructor] So, now I'm going to go ahead and implement the observable, which in this example is the connection class. So, I'm going to open up the connection class, and the first thing I'm going to do is I'm going to add a new field of type property change support, which I'll call support. And so I'm going to assign this to a new property change support instance. And I'm going to pass in this. This property change support is going to notify the observer when a property in this class changes. Now I need to edit the set status method. In this method, I'm passing in a string and setting the status fields to that value. I also want to let the observer know that the field has changed, so I need to add a line at the start of the method. And I'm going to use the support that I just created, so I'm going to do support, and I'm going to call a method called fire property change. I need to pass in three arguments to…

Contents