LOL in Java

Source: Internet
Author: User

Someone with a certain coding experience will be able to master some of the commonly used design patterns unconsciously.

Design patterns in my perception is that coding routines to solve specific problems of best practice. Just like playing lol, there are different ways of fighting and taking an impossible strategy.

Novice just understand the abstract concept in the design pattern is prone to a blank face (no specific application scenarios are really difficult to master), and veteran often familiar.

In fact, many aspects of the thinking is figured out, design mode of thinking is not limited to programming! We can not only thinking in Java, but also LOL in Java!

"Initial knowledge design mode" module, will be some common design patterns of superficial records. For example, it is also easier to accept these abstract concepts by using the idea of LOL.

Learn design patterns with LOL, so easy!

Below are some concepts of the pasted design pattern:

What is the design pattern?

Design patterns are a set of reusable, most known, categorized purposes, code design experience Summary.

Design patterns are used to reuse code, make code easier for others to understand, and ensure code reliability.

There is no doubt that design patterns in their own systems are multi-win, design patterns so that code is truly engineering, design patterns are the cornerstone of software engineering, as the structure of the building.

Overall, the design pattern is divided into 3 major categories totaling 23 kinds:

1, create a model, a total of 5

Factory method mode, abstract Factory mode, singleton mode, builder mode, prototype mode

2. Structure mode, total 7 kinds

Adapter mode, adorner mode, appearance mode, bridging mode, combined mode, enjoy meta mode

3, behavioral mode, a total of 11

Policy mode, template method mode, observer pattern, iterator mode, responsibility chain mode, Command mode, Memo mode, state mode, visitor mode, mediator mode, interpreter mode

Six Principles of design pattern

1. Open and closed principle OCP

The open and closed principle is that opening to the extension and closing the modification . When the program needs to be extended, it is not possible to modify the original code, which is also to make the program more extensible, easy to upgrade and maintenance.

2, the Richter substitution principle LSP

Replace a base class object with its subclass object in the software, and the program will not produce any errors or exceptions, which in turn is not true. If a software entity is using a subclass object, it must not be able to use the base class object. The procedural manifestation of the principle of substitution of the Richter scale is to use the base class type to define the object in the program, and then determine its subclass type at run time, substituting the parent class with the subclass object.

3. Control reversal Principle IOC

Programming for interfaces, relying on abstraction rather than on specific

4. Interface Isolation principle ISP

Using multiple isolated interfaces is better than using a single interface

5, Dimitri Law DP

An entity should interact with other entities as little as possible, making the system function modules relatively independent

6. Principle of synthetic reuse

Try to use the combination/aggregation approach instead of using inheritance

Three keywords in a design

1. Abstraction

Extracting common and essential features in many things, discarding non-essential features, is abstraction. The process of abstraction is also a process of tailoring, which, when abstracted, is different, depending on what angle it is abstracted from. The abstract angle depends on the purpose of the analysis problem.

2, realization of the

The concrete implementation of abstract class is realization.

An instance of a class is an instantiation of this class, and a concrete subclass is an instantiation of its abstract superclass.

3. Decoupling

This is more important, usually we always agreed that the code should be "high cohesion, low coupling", then what is the coupling?

The so-called coupling is a strong association of the behavior of two entities . and removing the strong association between them is decoupling. Decoupling is to untie the coupling between abstraction and implementation, or to change the strong association between them into weak associations.

The so-called Strong Association, refers to the compile time has been determined, can not be dynamically changed during the runtime of the Association, so-called Weak association, it can be dynamically determined and dynamic change in the run time of the association . From this definition, the inheritance relationship is strongly correlated, and the aggregation relationship is a weak association.

LOL in Java

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.