import java.util.ArrayList; import java.util.List; // Observable interface representing the social media feed interface Feed { void postUpdate(String update); void addFollower(Follower follower); void notifyFollowers(); } // Follower interface representing the followers interface Follower { void receiveUpdate(String update); } // Concrete observable representing the social media feed class SocialMediaFeed implements Feed { private List followers = new ArrayList<>(); private String update; @Override public void postUpdate(String update) { this.update = update; notifyFollowers(); } @Override public void addFollower(Follower follower) { followers.add(follower); } @Override public void notifyFollowers() { for (Follower follower : followers) { follower.receiveUpdate(update); } } } // Concrete SocialMediaFollower representing a Follower class SocialMediaFollower implements Follower { private String name; public SocialMediaFollower(String name) { this.name = name; } @Override public void receiveUpdate(String update) { System.out.println(name + " received update: " + update); } }