Observer-io (File Monitor)

Source: Internet
Author: User

1. Overview

Sometimes referred to as the Publish/subscribe pattern, the Observer pattern defines a one-to-many dependency that allows multiple observer objects to listen to a Subject object at the same time. This subject object notifies all observer objects when the state changes, enabling them to automatically update themselves.

2. Issues to solve

Splitting a system into a class in which some classes work together has a bad side effect, which is the need to maintain consistency among related objects. We do not want to be tightly coupled in order to maintain consistency, which can cause inconvenience to maintenance, expansion, and reuse. The observer is the solution to this kind of coupling relationship.

3. Roles in the pattern

3.1 Abstract Theme (Subject): It saves references to all observer objects in a single aggregation, each subject can have any number of observers. Abstract topics provide an interface that allows you to add and remove observer objects.

3.2 Specific topics (ConcreteSubject): deposit the relevant state into a specific observer object, and give notice to all registered observers when changes are made to the internal state of the specific subject.

3.3 Abstract Observer (Observer): Define an interface for all specific observers and update yourself when you get a topic notification.

3.4 Specific Observer (CONCRETEOBSERVER): Implements the update interface required by the abstract observer role in order to reconcile its state with the subject state.

This selects the Apache Commons IO Monitor to analyze the observer pattern.

Observer-io (File Monitor)

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.