java--Observer Pattern (Observer)--design mode XV

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.