Bây giờ các chủ đề đang theo dõi của hai quan sát viên. Khi một sự kiện xảy ra, chủ đề thông báo cho cả hai quan sát viên. (Xem hình 1-10.) Hình 1-10: Khi sự kiện xảy ra trong các chủ đề, các quan sát viên đã đăng ký được thông báo | 80 Part I Getting to Know Patterns_ You can either build in getter setter methods into the Observable object or put together an object with all the data you want to send to observers and pass that object to the notifyObservers method that object will then be passed as the second argument to the update method of the observers. I m going to modify the database example to use Java s Observer Observable as an example and I ll use the first technique adding getter setter methods to the Observable object here. Creating the Observable object To create a subject you extend the Observable class so here s how I create the new version of the Database class import import public class Database extends Observable public Database To let users make changes to the database I add the editRecord method which is passed both the operation to perform and the record in question passed as strings to make the code easier . The editRecord method stores the operation and record then calls the setChanged and notifyObservers methods to pass that new data along to the observers. import import public class Database extends Observable private String operation private String record public Database public void editRecord String operation String record Chapter 4 The Observer and Chain of Responsibility Patterns 81 operation record setChanged notifyObservers When the observers are called they re passed the Database object so I add getter methods to let code retrieve the database operation and affected record from that object. import import public class Database extends Observable private String operation private String record public Database public void editRecord String operation String record operation record setChanged notifyObservers public String getRecord return record .