1 design pattern

Interview Topic - Design Patterns

foreword

In the usual development, there are two pieces of content related to the design pattern. The first is the framework we usually use (such as spring, mybatis, etc.), and the second is the design pattern we use to develop our own business.

Interviewers are generally more concerned about whether you have used design patterns during the development process, or you have written a description of design patterns on your resume, so we need to focus on the design patterns we have used in our development.

In normal business development, in fact, there are not many scenarios where design patterns are actually used. Although there are as many as 23 designs (there may be more in different latitudes), there are only a few that are most commonly used in projects. During the interview process, we only need to introduce one or two types. The key point is: in what business scenario is the design pattern used, and what design pattern?

image-20230521101639915

In this interview part, we mainly introduce three design patterns:

  • Factory method pattern (simple factory, factory method, abstract factory)
  • strategy pattern
  • chain of responsibility model

1 Factory method pattern

1.1 Overview

Requirements: Design a coffee shop ordering system.

Design a coffee class (Coffee) and define its two subclasses (American Coffee [AmericanCoffee] and Latte Coffee [LatteCoffee]); design a coffee shop class (CoffeeStore)

Guess you like

Origin blog.csdn.net/m0_65030141/article/details/131253733