Understanding of Java design patterns and Java Design Patterns

Source: Internet
Author: User

Understanding of Java design patterns and Java Design Patterns
What is the design pattern? Design pattern is a set of summary of code Design experiences that are repeatedly used, known to most people, classified and catalogued.
In essence, it is a combination of inheritance and interfaces. Why do we need a design model? The design pattern is used to make code reusable, make it easier for others to understand, ensure code reliability, and improve work efficiency. Classification of design patterns: there are 23 types of design patterns by purpose.

  • Creation Mode: Singleton mode, abstract factory mode, builder mode, factory mode, and prototype mode.
  • Structural Mode: Adapter mode, bridging mode, decoration mode, combination mode, appearance mode, metadata mode, and proxy mode.
  • Behavior mode: Template Method mode, command mode, iterator mode, observer mode, intermediary mode, memorandum mode, interpreter mode, status mode, policy mode, responsibility chain mode, and visitor mode.

Factory mode Demo:
Interface Fruit {// define a Fruit interface public void eat (); // eat Fruit} class Apple implements Fruit {public void eat () {System. out. println ("** eat apple. ") ;}}; Class Orange implements Fruit {public void eat () {System. out. println (" ** eat oranges. ") ;}}; Class Factory {// defines the Factory class public static Fruit getInstance (String className) {Fruit f = null; if (" apple ". equals (className) {// determines whether the Child class of Apple is required. f = new Apple ();} if ("orange ". equals (className) {// determines whether the Sub-class f of the Orange is new Orange ();} return f ;}}; public class InterfaceCaseDemo05 {public static void main (String args []) {Fruit f = Factory. getInstance (args [0]); // instantiate the interface if (f! = Null) {// determine whether to obtain the instance f. eat ();}}};



How can I better understand the java design pattern?

Main Learning: Singleton mode, factory mode (simple factory mode, factory method mode, abstract factory mode) combination mode, observer mode, status mode. Use the code to implement these modes, and draw out their processes for visual understanding !!

Which design patterns are commonly used in java?

There are 23 design modes in total!

According to the purpose, the design patterns can be divided into creation patterns, structural patterns, and behavior patterns.
The creation mode is used to process the object creation process, the structure mode is used to process the combination of classes or objects, and the behavior mode is used to describe how classes or objects interact and how responsibilities are assigned.

The creation mode is used to process the object creation process. It mainly includes the following five design modes:
Factory Method Pattern)
Abstract Factory Pattern)
Builder Pattern)
Prototype Pattern)
Singleton Pattern)

The structural mode is used to process the combination of classes or objects. It mainly includes the following seven design modes:
Adapter Pattern)
Bridge Pattern)
Composite Pattern)
Decorator Pattern)
Facade Pattern)
Flyweight Pattern)
Proxy Pattern)

The behavior pattern is used to describe how classes or objects interact and how responsibilities are assigned. It mainly includes the following 11 design patterns:
Chain of Responsibility Pattern)
Command Pattern)
Interpreter mode (Interpreter Pattern)
Iterator Pattern)
Mediator Pattern)
Memory memorandum mode (Memento Pattern)
Observer Pattern)
State Pattern)
Strategy Pattern)
Template Method Pattern)
Visitor Pattern)

We recommend that you have a good book: "software tips: the point of design patterns", in which 23 examples of design patterns are very vivid and easy to understand, as well as the application of design patterns in JDK, I saw a big harvest! Baidu searches for "design patterns", and the first design patterns in Baidu encyclopedia are the first to push the book. If the number of views is more than, it will not be wrong. Let's share some good things!
I wish you an early learning of the design model!

Related Article

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.