Blog: bugstack.cn

Precipitation, share, grow, let yourself and others can gain something! 😄

directory

  • One, foreword
  • Second, the introduction of
    • 1. Who invented design patterns?
    • 2. How can I not learn design patterns?
    • 3. Fit the crowd
    • 4. What can I learn
    • 5. Read the advice
  • The contents of the book
    • 1. Create the schema
    • 2. Structural mode
    • 3. Behavior patterns
  • 4. Download PDF📚
    • 1. The available content includes
    • 2. Obtaining method
  • Five, close a tail 🎉

One, foreword

I inflated 💥, and after writing the last PDF book bytecode Programming, which has been downloaded for 2000 copies, started planning the second one. Therefore, I devoted myself to the practical design mode from 🌹 on May 20, and explained the design mode by simulating the actual needs of Internet business development as a learning scene.

The book has 22 real business scenarios corresponding to 59 groups of case projects, and compiled a PDF of 180,000 words and 271 pages, which took 50 days to complete from May 20.


💋 In view of the author’s limited level, if the book contains difficult to understand the content, must be the author in the process of writing the lack of necessary description and strict calibration, thank you for your opinions or questions submitted to me, but also welcome to interact with me more, mutual progress and growth together.

Second, the introduction of


Welcome to the site. I’m glad you’re getting this ebook. If you stick to it and follow the examples, you’ll have one more person in the programming world who can write good code, and one more person who can train architects.

You may have seen design patterns before, but they are rarely used in actual business development. Most of the time, they are used to assemble business processes by accumulating ifelse on a large scale, and you can only make up Ctrl+C, Ctrl+V for iteration of requirements and logical additions.

Therefore, in order to let more programmers 👨💻 better accept the design and architecture thinking, and can apply to the actual business scenarios. The author of this book, Fu Ge, invested 50 days, from the Actual business development of the Internet out of the transaction, marketing, seconds kill, middleware, source code and other 22 real scenes, to learn the application of design mode practice can be used to get started skills.

1. Who invented design patterns?

The concept of design pattern was first proposed by Christopher Alexander in his book Architectural Pattern Language. This book introduces the “language” of urban design, providing 253 models for describing the construction of towns, neighborhoods, houses, gardens, rooms and the west. The basic unit of this “language” is pattern. Later, four authors – Erich Gamma, John Friesides, Ralph Johnson, and Richard Helm – embraced the concept of patterns. In 1994, they published Design Patterns: The Foundation of Reusable Object-oriented Software, which applied the concept of design patterns to the field of program development.

There are a few people out there who haven’t read the books on design patterns and can still write great code. This is mainly due to the experience extracted from the years of programming process through the tempering of numerous projects and the continuous pursuit of programming. This lesson will ultimately be almost identical to the design pattern, which is highly cohesive, low coupled, scalable, and reusable. You’ve probably had the same experience learning the source code for a framework and finding that some of the design is the same as it was when you were developing.

2. How can I not learn design patterns?

Money was spent and books were bought. The code is still lumpy! Design patterns are developed from years of experience. It’s like when I tell you how to ride a bike or how to drive a car, but if you haven’t run thousands of kilometers, all you can remember is the theory, and it’s still a panic!

So, this design patterns series begins with the idea of using design patterns to optimize code. In order to learn design patterns and incorporate them into their own. Of course, there is a lot of practice to be done here, and it must be a combination of people and cars, so that we can build more reasonable code based on design patterns.

3. Fit the crowd

  1. Research and development personnel with programming experience of 1-3 years
  2. I hope this book can improve coding thinking and eliminate the bad taste in the code
  3. Willing to become an architect, but still at a bottleneck
  4. I studied design patterns, but I always wanted to find a book that could be used as a reference in real life

4. What can I learn

  1. Optimize ifelse statements in normal development to make code cleaner
  2. Look at the design pattern is no longer a theoretical rote, this can be a bit useful
  3. Stand in a higher perspective to look at programming development, learn more object-oriented thinking, especially; Interfaces, abstract classes, polymorphisms, etc
  4. Promotion, salary increase, good code is the basis of efficiency improvement, become the most beautiful coding spirit of the group

5. Read the advice

This book belongs to practical rather than theoretical introduction of the kind of books, each chapter has a corresponding complete code, the learning process needs to reference the book chapter and code together, at the same time in the process of learning need to understand and run the code. After learning, summarize the knowledge points and think about how to use the design mode like 🤔 in our own business scenarios.

The contents of the book

Design patterns follow six principles; Single responsibility (a class and method to do only one thing), magnitude of replacement (polymorphism, subclasses can extend the superclass), dependency inversion (details depend on abstract, lower dependence on top), the interface segregation () to create a single interface, di milt principle (at least know, reduce the coupling), the open closed principle (abstract architecture, extension implementation), in the specific design pattern sections, to reflect.

1. Create the schema

This type of pattern provides a mechanism for creating objects that can improve the flexibility and reusability of existing code.

The serial number type then The business scenario Realize the point
1 The factory method Various types of goods with different interfaces, unified prize awarding service set up scenes Define an interface to create an object and let subclasses decide which factory class to instantiate. The factory pattern delays the creation of the object until the subclass.
2 The abstract factory Replace Redis dual cluster upgrade, proxy class abstract scene Provides an interface for creating a series of related or interdependent objects without specifying their concrete classes.
3 The generator Various decoration materials combination package selection scenarios Separating a complex build from its representation allows the same build process to create different representations.
4 The prototype On the computer test more than a set of tests, each topic and the answer disorderly arrangement of the scene Specify what kind of objects to create with prototype instances, and create new objects by copying these prototypes.
5 The singleton The Effective Java authors recommend enumerating the seven singleton patterns Ensure that a class has only one instance and provide a global access point to access it.

2. Structural mode

This type of pattern describes how to assemble objects and classes into a larger structure while keeping the structure flexible and efficient.

The serial number type then The business scenario Realize the point
1 The adapter Extract the specified field value scenario from multiple MQ message bodies Translate the interface of a class into another interface that the customer wants. The adapter pattern makes it possible for classes to work together that would otherwise not work because of interface incompatibilities.
2 The bridge Multiple payment channels (wechat, Alipay) and multiple payment modes (face brushing, fingerprint) scenarios Separate the abstract parts from the implementation parts so that they can be changed independently.
3 combination Marketing differentiated crowd coupons, decision tree engine to build scenes Group objects into a tree structure to represent a partial-whole hierarchy. The composite pattern makes the use of single objects and composite objects consistent.
4 decoration The SSO SSO function is extended to add the blocking user access method scope scenario Add some extra responsibilities to an object dynamically. Decorator patterns are more flexible in terms of adding functionality than subclassing.
5 appearance Based on SpringBoot to develop the facade mode middleware, unified control interface whitelist scenario To provide a consistent interface for a set of interfaces in a subsystem, the facade defines a high-level interface that makes the subsystem easier to use.
6 The flyweight Provides activity and inventory information query scenarios based on Redis Use sharing techniques to effectively support a large number of fine-grained objects.
7 The agent Simulation of mybatis- Spring defined DAO interface, using proxy class to operate the database principle implementation scenario Provide a proxy for other objects to control access to that object.

3. Behavior patterns

This type of pattern is responsible for effective communication between objects and delegation of responsibilities.

The serial number type then The business scenario Realize the point
1 Chain of responsibility Simulate the multi-level responsible person approval scenario of project launching process during the 618 e-commerce promotion period Avoid coupling the request sender with the receiver, make it possible for multiple objects to receive the request, connect the objects into a chain, and pass the request along the chain until an object handles it.
2 The command Simulate eight major cuisines in high-end restaurants, and cook the scene with a single chef Encapsulate a request into an object, allowing you to parameterize customers with different requests.
3 The iterator It simulates the tree structure relationship of the company’s organizational structure and iterates deeply the personnel information output scene Provides a way to access elements of an aggregate object sequentially without exposing the internal representation of the object.
4 broker According to Mybatis principle handwritten ORM framework, add the intermediary scene to JDBC mode operation database By encapsulating a set of object interactions with a mediation object, the mediator loosens the coupling of objects without explicitly referring to each other, and can change their interactions independently.
5 The memo This simulation simulates the configuration file rollback scenario when an Internet system is online Capture the internal state of an object and store the state outside of the object without breaking encapsulation.
6 The observer The simulation is similar to the small bus index lottery process, and the monitoring message notifies the user of the winning scenario Defines a one-to-many dependency between objects in which all dependent objects are notified and automatically updated when an object’s state changes.
7 state Simulate system marketing activities, status process review and release online scene Allows an object to change its behavior when its internal state changes, and the object appears to modify its class.
8 strategy Simulate a variety of marketing types of coupons, discount amount calculation strategy scenarios Define a set of algorithms, encapsulate them one by one, and make them interchangeable.
9 Template method Simulate all kinds of crawler e-commerce commodities and generate marketing promotion poster scenes Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. The template approach allows subclasses to redefine specific steps of an algorithm without changing the structure of that algorithm.
10 The visitor Simulate parents and principals, students and teachers from different perspectives of information interview scene The main separation of data structures from data operations.

The above drawings and part of the description for reference; https://refactoringguru.cn, https://www.runoob.com/design-pattern/visitor-pattern.html

4. Download PDF📚

Before downloading, a little support for the original author is requested at 😬, like, view, share, comment, praise, and complete any of them to receive 🉐.

1. The available content includes

  1. Relearning Java Design PatternsA PDF Book
  2. 59 corresponding project case source code set
  3. Read the materials online

2. Obtaining method

  1. Scan the qr code below plus column learning group, all who join will send a book
  2. Add Fustack to get PDF books
  3. Reply to the PDF download inside the public account and you will get a link to the right after opening itThe menu -> select -> A good book worth reading, which also has the corresponding book 📚

Five, close a tail 🎉

👣 through the road will leave footprints, 👨💻 code over the text will fill the four seasons.

Sometimes I really appreciate that I still persist in doing original technical output. Even though I am busy and tired, I give myself an explanation for the present. In the process of writing the article, I almost never spend weekends or midnight. But when I finish each article, that effort for myself also spreads to others technical knowledge. I also hope readers can give me more views and comments, which is almost the biggest motivation to support my writing feedback

This book is a design mode of actual combat book 📚, in the process of writing often to find a suitable and easy to understand the scene and scratch your hair, and even sleep in the dream of the appropriate content, but also to use voice to send their own records. Fortunately, it took 50 days to write all 22 design mode scenarios. If there is something in the book that is not easy to understand, do not worry that it must be because the author has not described clearly or found cases that are not suitable. You can add the author Fustack’s wechat to exchange the corresponding technical content and make progress together.

Finally, I want to say: ability is the biggest guarantee for you to move forward. Even if you are a conscientious worker, but also have the ability to stay and jump out of the ability, will be relatively stable through the turbulence.