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 observer

Implementing an observer - Java Tutorial

From the course: Java Design Patterns: Behavioral Part 2

Start my 1-month free trial

Implementing an observer

- [Instructor] In this example, I have a simple implementation of a social media network. I want to make it so that when one of my connections updates their status, it will show up in my feed. So let's have a look at the code so far. First of all, we have a class called connection, which represents a person I'm connected to on the sites. This class has a single field called status, which is of type string, and is initially set to just an empty string. And there's also a method called getStatus, which sets the status field to the string that's passed in. Next, let's have a look at the SocialMediaFeed class. This also has a single field called statuses, which is an array list of strings. This represents all of the statuses of all of my connections. There's also a method called printStatuses, which prints out every status in the list to the console. Finally, there is a main class with a main method in it. In this main method…

Contents