Generally speaking, the following eight kinds of design patterns are commonly used: single example, factory, observer, Agent, command, adapter, synthesis, visitor
Single case mode: The goal is to have only one calling object in the system, the disadvantage of which is that it makes other programs rely too much on it, and that different single cases run in different processes, making maintenance difficult;
, generally long-term, and the relationship between the two is generally equal.(2) In the dependency relationship, it is simple to understand that a class A uses another Class B, which is contingent, temporary, and very weak, but changes in class B affect a.4. Comprehensive comparisonThese relationships are semantically level, so it is not possible to completely differentiate the relationships from the code level, but in general, the latter relationships are shown in the following ways:Combinati
First, this program is marked
What is a singleton mode
Single-Instance pattern class diagram
Singleton Pattern Code
Application of single-case model
Ps:java design Mode Series course, this is the last section of the class. I believe that we learn all the way down or harvest quite abundant, now think back to the learning of those design
I will divide the recommended books according to the elementary, intermediate, and advanced categories. And write it according to the format-name, language, content comments, and recommendation index :).Elementary: I think the basic standard is to explain what the model is and the introduction of common models.1.Name: head first design patternsLanguage: JavaComments: Jolt Award winner, who introduced more
Six principles in Design Patterns
ISingle Responsibility Principle
1,
Singleresponsibilityprinciple (SRP) has only one reason for its change in a class.
2, Description
Excessive class responsibilities = coupling the responsibilities together may lead to the entire body, resulting in the class being unable to fulfill other responsibilities. This high coupling will lead to fragile
1. gof's design pattern is the source of all design patterns. However, all the examples in this book are based on C ++.
2. o'reilly's head first design patterns, an entry-level book
3. This book is also good.
4. Introduction to
appear in memory!There are many ways to solve thread insecurity, you can add synchronized keywords before the Getsingleton method, or you can add synchronized to the Getsingleton method, but none of the best singleton patterns It is recommended that the reader use the same method as shown in Listing 7-3 (some books refer to the singleton in Listing 7-3 as the A Hungry Man Singleton, and a single example of synchronized in code listing 7-4 is called a
its grammar and provide an interpreter at the same time. The client can use this interpreter to interpret the sentences in the language. The interpreter pattern will describe how to interpret these statements using pattern design after having a simple grammar. The language mentioned in the interpreter mode refers to any combination that any interpreter object can interpret. In the interpreter pattern, you need to define a hierarchy of command classes
1. What is prototype mode? (what)Prototype mode is a creation design pattern, it is a copy of the way to quickly create an object, there are two ways to copy: 1.) Shallow copy (pointer copy); 2.) deep copy (value copy); Creating a new object with prototype mode is more efficient.what are deep and shallow copies? (what)A deep copy is also called a value copy, and the newly created object will open up new space in memory and copy the value of the copied
code is as follows: The code for Mutequack is as follows: So now you just need to test to see the final result: end note:In fact, most of the content belongs to the transport, the original very few, but also deleted the original book part of the content, will slowly more practical understanding to explain a pattern, the first test of water, code is not all the small partners to write their own, do not Baidu, code this thing, although the wheel has been created, but their own side, Will understa
Summary of common design patterns--responsibility chain model
In the multithreaded programming model, the responsibility chain pattern is a common pattern, the responsibility chain model can decompose a task into small independent task units, so that the whole task at a glance.
Take a crawler to crawl a page for example, assuming that the URL of the scheduling is not a crawler to manage, but there is a spec
The observer pattern is simple to say, a pattern of newspaper-ordering. But in fact this Part I think is still very interesting, "Head first design mode" There are still some not read, but also because the understanding is not deep enough.The observer pattern consists of two components: The Observer and the subject.This code is the interface of the topic: Package Obeserver; Public Interface Subject { pu
thread safety while ensuring execution efficiency. I have been asked why I should judge if (Sinlenton = = null) in synchronized, and I personally understand that this is the reason:If two threads are executed to the first if (singleton = = null) and both are true, this is always a line enters upgradeable into synchronized (Singleton.class) ... Part of the code and block another entry. When the first entry is completed and an instance singleton is successfully built, it is no longer blocked. Ano
() {System.out.println ("The red-headed duck, the head is red"); }} Test: Public classTest { Public Static voidMain (string[] args) {test3 (); } Public Static voidtest3 () {Duck Duck=NewRedduck (); //Transsexual Squeak//rocket tied up, take a look at the flight effectDuck.setflyable (Newrocketfly ()); Duck.dispaly (); Duck.swim (); Duck.fly (); }} template mode: Public classbenz{ Public voidstart () {System.out.println ("Me
facade façade that invokes the logic handler, what should we do if the logical handler has an exception?2. What do we need to do to deal with the results of logical processing to meet the rich foreground display needs?This one-on-one problem is based on the mining of the basic concepts of MVC. So, all of these questions need to be solved one by one when we write the program. Speaking of which, the questions raised at the beginning of this article should be answered: The framework is designed to
General principles in Design Patterns
I. "open-closed" principle (OCP)The principle of open-closed principle is that a software entity should be open to extensions and closed to modifications.Advantages:New behaviors can be provided by extending existing software systems. The existing software modules, especially the most important abstraction layer modules, cannot be modified, which makes the sof
prototype methods are added to the sub-class.Instance1.colors.push (' black '); Console.log (instance1.colors); // [' Red ', ' blue ', ' green ', ' black '] // [' Red ', ' blue ', ' green ']instance1.getname (); // CSSbook instance2.gettime (); // -Note: A subclass that wants to add a prototype method must pass a prototype object, one way to add it through the form of a point syntax, or it will be directly assigned to an object that overrides the inherited object from the parent class p
to deal with the bug ... * in this way, the original technical director to handle the bug, now a layer of responsibility to the programmer to deal with the */handler1.sethandler ( HANDLER2); Handler2.sethandler (HANDLER3);/** * Through the printing results can be known: MyHandler instantiation will generate a series of mutually held objects (handler), forming a chain. */handler1.operator ();/** * "Note 2" The chain of responsibility is not linked list: The list has a
The importance of design patterns in object-oriented objects.
More in-depth understanding of object-oriented thinking, is conducive to the development of highly scalable programs. There is a "closing principle" in the PHP object-oriented: "Software entities should be open to extensions and closed to modifications." Popular saying: Add new class/interface, etc. come in line, modify not. 1. Factory mode
In
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.