Viewing design Patterns from Java class libraries (1)

Source: Internet
Author: User

In this section, we introduce a relatively simple but powerful pattern: Observer mode. Hope that through this part of the narrative, we have seen, can have a more comprehensive design model, perceptual understanding.

Often, experience is critical for a design (software, architecture, or it's industrial). Good experience gives us guidance and saves us time, and bad experiences give us lessons that can reduce the risk of failure. However, from the knowledge level, experience is only as an accumulation of work in the individual's brain, it is difficult to be taught or recorded. In order to solve such problems, people put forward the concept of the so-called model. The so-called pattern refers to a recurring problem solution in a particular context. Patterns are the documentation of experience.

The concept of software patterns is now more extensive, involving analysis, design, architecture, coding, testing, refactoring and other software constructs in various parts of the life cycle. Here the main discussion is the design pattern, refers to in the software design process repeatedly appears some problem solution. However, we generally refer to the design pattern, usually refers to the Gof classic book, "Designing Pattern--elements of the reusable object-oriented Software," the 23 patterns, thus, It is the specific needle for object-oriented software design process.

In the overall sense, the pattern represents a language, a documented experience, or even a culture. Often a lot of inconvenient description, or describe a very complex problem, using the pattern language to narrate, will let the listener have the feeling of empathy. Of course, this requires both sides to communicate a good grasp of the meaning of the model language. However, this is not an easy thing. The pattern is often different in each person's understanding, this article aims at a concrete application angle: Java class Library, to narrate the design pattern. Combined with concrete examples, we hope to deepen our understanding of design patterns.

The Java class Library here is not limited to the JDK itself, but includes examples of other class libraries, such as JAXP (and, of course, the next version of JDK includes JAXP). In fact, the idea of design pattern is now applied so widely, no matter in what kind of design, as long as a little larger design, can find many many design patterns of traces, or that are unavoidable use of design patterns. The design patterns described below are mostly the 23 patterns that appear in Gof's classic, yet there are some, such as MVC, that do not belong there. Generally speaking, we think that the 23 models of GOF are some intermediate mode, under it can also abstract some more general low-level mode, on which can also be combined to get some advanced mode. Of course, here the difference between the low and the high, as the difference between different languages, there is no good or bad points, only in the application level of the difference.

Observer mode

The function of the observer model is to hope that two (or more) objects, which we call subject and observer, can be notified when one party's state changes. That is, as a observer, it is possible to monitor and respond to a particular state change in the subject. A simple example is that when the data in a user view is changed by the user, the backend database is updated and the data in the user's view changes as the database is updated in other ways.

Figure I: Class diagram of the Obverser pattern

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.