[source code analysis and design mode 2, 40 pictures and texts, I don't believe you can't understand concurrent programming

4. Specific products

It implements the interface defined by the abstract product role, which is created by the specific factory. It has a many-to-one relationship with the specific factory.

3, Advantages and disadvantages

1. Advantages

  • The multi-level products associated in the product family can be managed together within the class, instead of introducing multiple new classes for management;

  • When adding a new product family, there is no need to modify the original code to meet the opening and closing principle.

2. Shortcomings

When a new product needs to be added to the product family, all factory classes need to be modified.

4, After reading Head First design pattern

1. The abstract factory pattern provides an interface for creating families of related or dependent objects without explicitly specifying specific classes.

2. The factory method pattern uses inheritance, and the abstract factory pattern uses the combination of objects.

5, JDK source code analysis

package com.guor.jdk;

import java.util.Calendar;

public class Factory {

    public static void main(String[] args) {

        Calendar cal = Calendar.getInstance();

        // Note that the month subscript starts from 0, so the month should be + 1

        System.out.println("year:" + cal.get(Calendar.YEAR));

        System.out.println("month:" + (cal.get(Calendar.MONTH) + 1));

        System.out.println("day:" + cal.get(Calendar.DAY_OF_MONTH));

        System.out.println("Time:" + cal.get(Calendar.HOUR_OF_DAY));

        System.out.println("branch:" + cal.get(Calendar.MINUTE));

        System.out.println("second:" + cal.get(Calendar.SECOND));



6, Code example

1. UML class diagram

2. Code architecture

3. Specific code

(1) order bag

package com.guor.abstractFactory.order;

import com.guor.abstractFactory.pizza.Pizza;

//Abstract layer (Interface) of an abstract factory pattern

public interface AbsFactory {

	//Let the following factory subclass implement it

	public Pizza createPizza(String orderType);


package com.guor.abstractFactory.order;

import com.guor.abstractFactory.pizza.BJCheesePizza;

import com.guor.abstractFactory.pizza.BJPepperPizza;

import com.guor.abstractFactory.pizza.Pizza;

//This is a factory subclass

public class BJFactory implements AbsFactory {


public Pizza createPizza(String orderType) {

	System.out.println("~The abstract factory pattern is used~");

	Pizza pizza = null;

	if(orderType.equals("cheese")) {

		pizza = new BJCheesePizza();

	} else if (orderType.equals("pepper")){

		pizza = new BJPepperPizza();


	return pizza;



package com.guor.abstractFactory.order;

import com.guor.abstractFactory.pizza.LDCheesePizza;

import com.guor.abstractFactory.pizza.LDPepperPizza;

import com.guor.abstractFactory.pizza.Pizza;

public class LDFactory implements AbsFactory {


	public Pizza createPizza(String orderType) {

		System.out.println("~The abstract factory pattern is used~");

		Pizza pizza = null;

		if (orderType.equals("cheese")) {

			pizza = new LDCheesePizza();

		} else if (orderType.equals("pepper")) {

			pizza = new LDPepperPizza();


		return pizza;



package com.guor.abstractFactory.order;

import com.guor.abstractFactory.pizza.Pizza;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class OrderPizza {

AbsFactory factory;

// constructor 

public OrderPizza(AbsFactory factory) {



private void setFactory(AbsFactory factory) {

	Pizza pizza = null;

	String orderType = ""; // User input

	this.factory = factory;

	do {

		orderType = getType();

		// Factory may be a factory subclass in Beijing or a factory subclass in London

		pizza = factory.createPizza(orderType);

		if (pizza != null) { // Order ok





		} else {

			System.out.println("Subscription failed");



	} while (true);


// Write a method to get the type of pizza customers want to order

private String getType() {

	try {

		BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));

		System.out.println("input pizza type:");

		String str = strin.readLine();

		return str;

	} catch (IOException e) {


		return "";



Spring full set of teaching materials

Spring is the "sunflower dictionary" of Java programmers, which provides various great tricks that can simplify our development and greatly improve development efficiency! At present, 99% of companies use spring. You can go to major recruitment websites. Spring is a necessary skill, so you must master it.

CodeChina open source project: [analysis of Java interview questions of front-line large manufacturers + core summary learning notes + latest explanation Video]


Some contents:

Spring source code

  • Part I overview of Spring
  • The second part is the core idea
  • The third part is the implementation of IoC and AOP (custom Spring framework)
  • Part IV advanced application of Spring IOC
    Basic characteristics
    Advanced features
  • The fifth part is the in-depth analysis of Spring IOC source code
    Elegant design
    Design pattern
    Note: principles, methods and techniques
  • Part VI Spring AOP application
    Declare transaction control
  • The seventh part is the in-depth analysis of Spring AOP source code
    Necessary notes, necessary drawings and easy to understand language to resolve knowledge difficulties

Scaffold framework: SpringBoot Technology

Its goal is to simplify the creation, development and deployment of Spring applications and services, simplify the configuration file, use embedded web server, contain many out of the box microservice functions, and can be jointly deployed with spring cloud.

The core idea of Spring Boot is that convention is greater than configuration. Applications only need a few configurations, which simplifies the application development mode.

  • Getting started with SpringBoot
  • configuration file
  • journal
  • Web development
  • Docker
  • SpringBoot and data access
  • Startup configuration principle
  • Custom starter

Microservice architecture: Spring Cloud Alibaba

Like Spring Cloud, Spring Cloud Alibaba is also a set of microservice solutions, including the necessary components for developing distributed application microservices, so that developers can easily use these components to develop distributed application services through the Spring Cloud programming model.

  • Introduction to microservice architecture
  • Introduction to Spring Cloud Alibaba
  • Microservice environment construction
  • Service governance
  • Service fault tolerance
  • Service gateway
  • Link tracking
  • ZipKin integration and data persistence
  • Message driven
  • SMS service
  • Nacos config - service configuration
  • Seata - distributed transactions
  • Dubbo rpc communication

Spring MVC


Some contents:

  • Message driven
  • SMS service
  • Nacos config - service configuration
  • Seata - distributed transactions
  • Dubbo rpc communication

[external chain picture transferring... (img-yL4NAFym-1630928867151)]

[external chain picture transferring... (img-FuD3yTKL-1630928867152)]

Spring MVC


[external chain picture transferring... (IMG pbengehx-1630928867152)]

[external chain picture transferring... (img-GLRrS0YD-1630928867153)]

[external chain picture transferring... (img-kIyQ4uJm-1630928867154)]

Some contents:

[external chain picture transferring... (img-4laTKGPy-1630928867154)]

[external chain picture transferring... (IMG nmwlhzmp-1630928867155)]

Tags: Back-end Programmer

Posted on Mon, 06 Sep 2021 22:27:26 -0400 by shorty114