1, Overview:
(1) This pattern is the relationship between classes and classes, and does not involve inheritance, the observer pattern is well understood, similar to the message
subscriptions and RSS feeds, when we look at blogs or wikis (Wikipedia), we often see RSS icons, whichis to say, when you subscribe to the article, if there are updates, will notify you in a timely manner, in fact, a simple sentence is said: whenwhen an object changes, other objects that depend on the object are notified, and as they change, the object is aa one-to-many relationship,
first explain the effect of these classes above: The Mysubject class is our main object, Observer1 andObserver2 is dependent on Mysubject objects, and when Mysubject changes, Observer1 and Observer2
The Abstractsubject class defines a list of objects that need to be monitored and can be modified: increaseor delete the monitored object, and be responsible for notifying objects that exist within the list when the Mysubject changesThe code is as follows:
2, use of the properties file:
(1) You can use the properties file to manage observer
(2) Steps:① First the right mouse button to create a new file, named XXX properties, this property fileIn addition to being able to do with the properties can also use XML to do the ② property file is stored in classpath (Bin is the classpath of our project)
③ Write the configuration in the configuration file.
④ Get the properties defined in the configuration file in Java code
java--Observer Mode (OBSERVER)--design mode 15