主頁 > 軟體設計 > 【原型設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

【原型設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

2023-04-24 10:25:37 軟體設計

簡介

原型模式(Prototype Pattern)是一種創建型設計模式,使你能夠復制已有物件,而無需使代碼依賴它們所屬的類,同時又能保證性能,

這種模式是實作了一個原型介面,該介面用于創建當前物件的克隆,當直接創建物件的代價比較大時,則采用這種模式,

如果你需要復制一些物件,同時又希望代碼獨立于這些物件所屬的具體類,可以使用原型模式,

作用

  1. 利用已有的一個原型物件,快速地生成和原型物件一樣的實體,
  2. 跳過建構式的約束,便于提升性能,

實作步驟

  1. 創建原型介面,并宣告克隆方法,
  2. 使用new運算子呼叫原型版本的建構式,
  3. 將子類建構式的直接呼叫,替換為對原型工廠方法的呼叫,

UML

 

Java代碼

基礎原型抽象類

// Shape.java 基礎抽象類
public abstract class Shape implements Cloneable {

  private int width;
  private int height;
  private String color = "";
  protected String type;

  public Shape() {

  }

  public String getType() {
    return type;
  }

  // 抽象方法,子類覆寫
  public abstract void draw();

  public void setWidth(int width) {
    this.width = width;
  }

  public int getWidth() {
    return this.width;
  }

  public int getHeight() {
    return this.height;
  }

  public void setHeight(int height) {
    this.height = height;
  }

  public void setColor(String color) {
    this.color = color;
  }

  public String getColor() {
    return this.color;
  }

  // 克隆方法
  public Object clone() {
    Object clone = null;
    try {
      clone = super.clone();
    } catch (CloneNotSupportedException e) {
      e.printStackTrace();
    }
    return clone;
  }

  @Override
  public String toString() {
    return String.format("{width = %s, height = %s, type = %s, color = %s }",
        this.width, this.height, this.type, this.color);
  }
}

具體原型者

// Circle.java 具體原型類,克隆方法會創建一個新物件并將其傳遞給建構式,
public class Circle extends Shape {
  public Circle() {
    super();
    type = "Circle";
  }

  @Override
  public void draw() {
    System.out.println("Circle::draw() method.");
  }
}
// Rectangle.java 具體原型類,克隆方法會創建一個新物件并將其傳遞給建構式,
public class Rectangle extends Shape {
  public Rectangle() {
    super();
    type = "Rectangle";
  }

  @Override
  public void draw() {
     System.out.println("Rectangle::draw() method.");
  }
}
// 具體原型類,克隆方法會創建一個新物件并將其傳遞給建構式,
public class Square extends Shape {
  public Square() {
    super();
    type = "Square";
  }

  @Override
  public void draw() {
    System.out.println("Square::draw() method.");
  }
}

客戶使用類

// Application.java 客戶呼叫方
public class Application {

  public List<Shape> shapes = new ArrayList<Shape>();

  public Application() {
  }

  public void addToShapes() {
    Circle circle = new Circle();
    circle.setWidth(10);
    circle.setHeight(20);
    circle.setColor("red");
    shapes.add(circle);

    // 添加clone
    Circle anotherCircle = (Circle) circle.clone();
    anotherCircle.setColor("pink");
    shapes.add(anotherCircle);
    // 變數 `anotherCircle(另一個圓)`與 `circle(圓)`物件的內容完全一樣,

    Rectangle rectangle = new Rectangle();
    rectangle.setWidth(99);
    rectangle.setHeight(69);
    rectangle.setColor("green");
    shapes.add(rectangle);
    // 添加clone
    shapes.add((Shape) rectangle.clone());
  }

  // 直接取出
  public Shape getShape(Integer index) {
    return this.shapes.get(index);
  }

  // 取出時候clone
  public Shape getShapeClone(Integer index) {
    Shape shape = this.shapes.get(index);
    return (Shape) shape.clone();
  }

  public void printShapes() {
    for (int i = 0; i < this.shapes.size(); i++) {
      Shape shape = this.shapes.get(i);
      System.out.println("shape " + i + " : " + shape.toString());
    }
  }

}

測驗呼叫

    /**
     * 原型模式主要就是復制已有的物件,而無需實體化類,從而提升實體化物件時的性能
     * 其實就是復制實體的屬性到新物件上,減少了執行構造的步驟
     */
    Application application = new Application();
    application.addToShapes();
    Shape shapeClone = application.getShapeClone(1);
    // 更改clone
    shapeClone.setColor("gray");
    System.out.println("shapeClone : " + shapeClone.toString());
    // 直接更改
    application.getShape(3).setColor("yellow");
    application.printShapes();

    // /*********************** 分割線 ******************************************/
    application.shapes.add(new Square());
    for (Shape shape : application.shapes) {
      shape.draw();
      System.out.println(shape.toString());
    }

C代碼

基礎原型抽象類

// func.h 基礎頭檔案
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

typedef struct Shape shape;
typedef struct Circle circle;
typedef struct Rectangle rectangle;
typedef struct Square square;

// 定義了Shape作為基礎介面,以便各形狀有統一型別
typedef struct Shape
{
    char name[50];
    int width;
    int height;
    char color[50];
    char category[50];
    void (*draw)(struct Shape *shape);
    struct Shape *(*clone)(struct Shape *shape);
    char *(*to_string)(struct Shape *shape);
    void (*set_width)(struct Shape *shape, int width);
    int (*get_width)(struct Shape *shape);
    void (*set_height)(struct Shape *shape, int height);
    int (*get_height)(struct Shape *shape);
    void (*set_color)(struct Shape *shape, char *color);
    char *(*get_color)(struct Shape *shape);
    void (*set_category)(struct Shape *shape, char *category);
    char *(*get_category)(struct Shape *shape);
} Shape;
Shape *shape_constructor(char *name);

typedef struct Circle
{
    char name[50];
    int width;
    int height;
    char color[50];
    char category[50];
    void (*draw)(struct Circle *shape);
    struct Circle *(*clone)(struct Circle *shape);
    char *(*to_string)(struct Circle *shape);
    void (*set_width)(struct Circle *shape, int width);
    int (*get_width)(struct Circle *shape);
    void (*set_height)(struct Circle *shape, int height);
    int (*get_height)(struct Circle *shape);
    void (*set_color)(struct Circle *shape, char *color);
    char *(*get_color)(struct Circle *shape);
    void (*set_category)(struct Circle *shape, char *category);
    char *(*get_category)(struct Circle *shape);
} Circle;
Circle *circle_constructor(char *name);

typedef struct Square
{
    char name[50];
    int width;
    int height;
    char color[50];
    char category[50];
    void (*draw)(struct Square *shape);
    struct Square *(*clone)(struct Square *shape);
    char *(*to_string)(struct Square *shape);
    void (*set_width)(struct Square *shape, int width);
    int (*get_width)(struct Square *shape);
    void (*set_height)(struct Square *shape, int height);
    int (*get_height)(struct Square *shape);
    void (*set_color)(struct Square *shape, char *color);
    char *(*get_color)(struct Square *shape);
    void (*set_category)(struct Square *shape, char *category);
    char *(*get_category)(struct Square *shape);
} Square;
Square *square_constructor(char *name);

typedef struct Rectangle
{
    char name[50];
    int width;
    int height;
    char color[50];
    char category[50];
    void (*draw)(struct Rectangle *shape);
    struct Rectangle *(*clone)(struct Rectangle *shape);
    char *(*string)(struct Rectangle *shape);
    void (*set_width)(struct Rectangle *shape, int width);
    int *(*get_width)(struct Rectangle *shape);
    void (*set_height)(struct Rectangle *shape, int height);
    int *(*get_height)(struct Rectangle *shape);
    void (*set_color)(struct Rectangle *shape, char *color);
    char *(*get_color)(struct Rectangle *shape);
    void (*set_category)(struct Rectangle *shape, char *category);
    char *(*get_category)(struct Rectangle *shape);
} Rectangle;
Rectangle *rectangle_constructor(char *name);

// 呼叫客戶端
typedef struct Application
{
    struct Shape **shapes;
    int shapes_length;
    void (*add_to_shapes)(struct Application *app);
    void (*add_shape)(struct Application *app, Shape *shape);
    Shape *(*get_shape)(struct Application *app, int index);
    Shape **(*get_shapes)(struct Application *app);
    Shape *(*get_shape_clone)(struct Application *app, int index);
    void (*print_shapes)(struct Application *app);
} Application;
Application *application_constructor();
// shape.c 基礎類,供各種具體形狀復用
#include "func.h"

// shape基礎抽象類,供子類繼承覆寫
// C沒有抽象和繼承,此處作為公共類存在
void shape_draw(Shape *shape)
{
  printf("\r\n Shape::draw()");
}

void shape_set_width(Shape *shape, int width)
{
  shape->width = width;
}

int shape_get_width(Shape *shape)
{
  return shape->width;
}

int shape_get_height(Shape *shape)
{
  return shape->height;
}

void shape_set_height(Shape *shape, int height)
{
  shape->height = height;
}

void shape_set_color(Shape *shape, char *color)
{
  strncpy(shape->color, color, 50);
}

char *shape_get_color(Shape *shape)
{
  return shape->color;
}

void shape_set_category(Shape *shape, char *category)
{
  strncpy(shape->category, category, 50);
}

char *shape_get_category(Shape *shape)
{
  return shape->category;
}

char *shape_to_string(Shape *shape)
{
  static char result[1024];
  sprintf(result, "[name = %s width = %d, height = %d, category = %s, color = %s]",
          shape->name, shape->width, shape->height, shape->category, shape->color);
  return result;
}

// 將指標指向同一記憶體的方式來實作clone
Shape *shape_clone(Shape *shape)
{
  Shape *copy = (Shape *)malloc(sizeof(Shape));
  memcpy(copy, shape, sizeof(Shape));
  strcat(copy->name, "(clone)");
  // printf("\r\n shape_clone: %s", copy->to_string(copy));
  return copy;
}

// 定義簡單結構體,復制基本屬性和draw函式
Shape *shape_clone2(Shape *shape)
{
  struct Shape copy = {
      .width = shape->width,
      .height = shape->height,
  };
  strcpy(copy.name, shape->name);
  strcat(copy.name, "[clone]");
  strcpy(copy.color, shape->color);
  strcpy(copy.category, shape->category);
  Shape *shape_copy = &copy;
  shape_copy->draw = shape->draw;
  // printf("\r\n shape_clone: %s", shape->to_string(shape_copy));
  return shape_copy;
}

Shape *shape_constructor(char *name)
{
  printf("\r\n shape_constructor() [構建Shape]");
  Shape *shape = (Shape *)malloc(sizeof(Shape));
  strncpy(shape->name, name, 50);
  shape->draw = &shape_draw;
  shape->clone = &shape_clone;
  shape->to_string = &shape_to_string;
  shape->set_width = &shape_set_width;
  shape->get_width = &shape_get_width;
  shape->set_height = &shape_set_height;
  shape->get_height = &shape_get_height;
  shape->set_color = &shape_set_color;
  shape->get_color = &shape_get_color;
  shape->set_category = &shape_set_category;
  shape->get_category = &shape_get_category;
  return shape;
}

具體原型者

// circle.c 具體原型類,復用父類方法,實作自己的draw函式,
#include "func.h"

// 重新定義draw函式
void circle_draw(Circle *shape)
{
  printf("\r\n Circle::draw()");
}

Circle *circle_constructor(char *name)
{
  printf("\r\n shape_constructor() [構建Circle]");
  Shape *shape = (Shape *)shape_constructor(name);
  Circle *circle = (Circle *)shape;
  circle->draw = &circle_draw;
  return circle;
}
// rectangle.c 具體原型類,復用父類方法,實作自己的draw函式,
#include "func.h"

// 重新定義draw函式
void rectangle_draw(Rectangle *shape)
{
  printf("\r\n Rectangle::draw()");
}

Rectangle *rectangle_constructor(char *name)
{
  printf("\r\n shape_constructor() [構建Rectangle]");
  Shape *shape = (Shape *)shape_constructor(name);
  Rectangle *rectangle = (Rectangle *)shape;
  rectangle->draw = &rectangle_draw;
  return rectangle;
}
// square.c 具體原型類,復用父類方法,實作自己的draw函式,
#include "func.h"

// 重新定義draw函式
void square_draw(Square *shape)
{
  printf("\r\n Square::draw()");
}

Square *square_constructor(char *name)
{
  printf("\r\n shape_constructor() [構建Square]");
  Shape *shape = (Shape *)shape_constructor(name);
  Square *square = (Square *)shape;
  square->draw = &square_draw;
  return square;
}

客戶使用類

// application.c 客戶呼叫方
#include "func.h"

void app_add_to_shapes(Application *app)
{
  Circle *circle = circle_constructor("circle");
  circle->set_category(circle, "Circle");
  circle->set_width(circle, 10);
  circle->set_height(circle, 20);
  circle->set_color(circle, "red");
  app->add_shape(app, (Shape *)circle);

  // 添加Clone
  Circle *another_circle = circle->clone(circle);
  another_circle->set_color(another_circle, "pink");
  app->add_shape(app, (Shape *)another_circle);
  // 變數 `another_circle(另一個圓)`與 `circle(圓)`物件的內容完全一樣,

  Rectangle *rectangle = rectangle_constructor("rectangle");
  rectangle->set_category(rectangle, "Rectangle");
  rectangle->set_width(rectangle, 99);
  rectangle->set_height(rectangle, 69);
  rectangle->set_color(rectangle, "green");
  app->add_shape(app, (Shape *)rectangle);
  // 再添加一個clone
  app->add_shape(app, (Shape *)rectangle->clone(rectangle));
}

void app_add_shape(Application *app, Shape *shape)
{
  app->shapes_length += 1;
  Shape **new_shapes = (Shape **)calloc(app->shapes_length, sizeof(Shape));
  // 復制原有陣列,并追加新內容到新陣列
  for (int i = 0; i < app->shapes_length - 1; i++)
  {
    new_shapes[i] = app->shapes[i];
  }
  new_shapes[app->shapes_length - 1] = shape;
  free(app->shapes);
  // 指向新陣列
  app->shapes = new_shapes;
}

Shape *app_get_shape(Application *app, int index)
{
  return app->shapes[index];
}

Shape **app_get_shapes(Application *app)
{
  return app->shapes;
}

Shape *app_get_shape_clone(Application *app, int index)
{
  Shape *shape = app->shapes[index];
  if (shape != NULL)
  {
    return shape->clone(shape);
  }
  return NULL;
}

void app_print_shapes(Application *app)
{
  for (int i = 0; i < app->shapes_length; i++)
  {
    Shape *shape = app->shapes[i];
    printf("\r\n shape%d: %s", i, shape->to_string(shape));
  }
}

// 給觀察者系結主題,同時把觀察者添加到主題串列
Application *application_constructor()
{
  printf("\r\n application_constructor() [構建Application]");
  Application *app = (Application *)malloc(sizeof(Application));
  app->shapes_length = 0;
  app->shapes = (Shape **)calloc(app->shapes_length, sizeof(Shape));
  app->add_to_shapes = &app_add_to_shapes;
  app->add_shape = &app_add_shape;
  app->get_shape = &app_get_shape;
  app->get_shapes = &app_get_shapes;
  app->get_shape_clone = &app_get_shape_clone;
  app->print_shapes = &app_print_shapes;
  return app;
}

測驗呼叫

#include "../src/func.h"

int main(void)
{
  printf("test start:\r\n");
  /**
   * 原型模式主要就是復制已有的物件,而無需實體化類,從而提升實體化物件時的性能
   * 其實就是復制實體的屬性到新物件上,減少了執行構造的步驟,
   */
  Application *application = application_constructor();
  application->add_to_shapes(application);
  Shape *shape_clone = application->get_shape_clone(application, 0);
  // SetColor需要介面中定義
  shape_clone->set_color(shape_clone, "gray");
  printf("\r\n shape_clone : %s", shape_clone->to_string(shape_clone));
  // 直接更改
  // application->get_shape(application, 3)->set_color(application->get_shape(application, 3), "yellow");
  application->print_shapes(application);

  /*********************** 分割線 ******************************************/
  // 追加一個Squre實體,相關屬性為空
  application->add_shape(application, (Shape *)square_constructor("square"));
  // 打不列印查看結果

  for (int i = 0; i < application->shapes_length; i++)
  {
    Shape *shape = application->shapes[i];
    shape->draw(shape);
    printf("\r\n shape_%d %s", i, shape->to_string(shape));
  }
}

更多語言版本

不同語言實作設計模式:https://github.com/microwind/design-pattern

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/551021.html

標籤:設計模式

上一篇:四大常用MQ的優缺點和應用場景選擇

下一篇:返回列表

標籤雲
其他(157976) Python(38094) JavaScript(25390) Java(17989) C(15215) 區塊鏈(8259) C#(7972) AI(7469) 爪哇(7425) MySQL(7140) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5328) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4559) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2430) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1960) Web開發(1951) HtmlCss(1923) python-3.x(1918) 弹簧靴(1913) C++(1910) xml(1889) PostgreSQL(1873) .NETCore(1855) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 面試突擊第一季,第二季,第三季

    第一季必考 https://www.bilibili.com/video/BV1FE411y79Y?from=search&seid=15921726601957489746 第二季分布式 https://www.bilibili.com/video/BV13f4y127ee/?spm_id_fro ......

    uj5u.com 2020-09-10 05:35:24 more
  • 第三單元作業總結

    1.前言 這應該是本學期最后一次寫作業總結了吧。總體來說,對作業的節奏也差不多掌握了,作業做起來的效率也更高了。雖然和之前的作業一樣,作業中都要用到新的知識,但是相比之前,更加懂得了如何利用工具以及資料。雖然之間卡過殼,但總體而言,這幾次作業還算完成的比較好。 2.作業程序總結 相比前兩個單元,此單 ......

    uj5u.com 2020-09-10 05:35:41 more
  • 北航OO(2020)第四單元博客作業暨課程總結博客

    北航OO(2020)第四單元博客作業暨課程總結博客 本單元作業的架構設計 在本單元中,由于UML圖具有比較清晰的樹形結構,因此我對其中需要進行查詢操作的元素進行了包裝,在樹的父節點中存盤所有孩子的參考。考慮到性能問題,我采用了快取機制,一次查詢后盡可能快取已經遍歷過的資訊,以減少遍歷次數。 本單元我 ......

    uj5u.com 2020-09-10 05:35:48 more
  • BUAA_OO_第四單元

    一、UML決議器設計 ? 先看下題目:第四單元實作一個基于JDK 8帶有效性檢查的UML(Unified Modeling Language)類圖,順序圖,狀態圖分析器 MyUmlInteraction,實際上我們要建立一個有向圖模型,UML中的物件(元素)可能與同級元素連接,也可與低級元素相連形成 ......

    uj5u.com 2020-09-10 05:35:54 more
  • 6.1邏輯運算子

    邏輯運算子 1. && 短路與 運算式1 && 運算式2 01.運算式1為true并且運算式2也為true 整體回傳為true 02.運算式1為false,將不會執行運算式2 整體回傳為false 03.只要有一個運算式為false 整體回傳為false 2. || 短路或 運算式1 || 運算式2 ......

    uj5u.com 2020-09-10 05:35:56 more
  • BUAAOO 第四單元 & 課程總結

    1. 第四單元:StarUml檔案決議 本單元采用了圖模型決議UML。 UML檔案可以抽象為圖、子圖、邊的邏輯結構。 在實作中,圖的節點包括類、介面、屬性,子圖包括狀態圖、順序圖等。 采用了三次遍歷UML元素的方法建圖,第一遍遍歷建點,第二、三次遍歷設定屬性、連邊,實作圖物件的初始化。這里借鑒了一些 ......

    uj5u.com 2020-09-10 05:36:06 more
  • 談談我對C# 多型的理解

    面向物件三要素:封裝、繼承、多型。 封裝和繼承,這兩個比較好理解,但要理解多型的話,可就稍微有點難度了。今天,我們就來講講多型的理解。 我們應該經常會看到面試題目:請談談對多型的理解。 其實呢,多型非常簡單,就一句話:呼叫同一種方法產生了不同的結果。 具體實作方式有三種。 一、多載 多載很簡單。 p ......

    uj5u.com 2020-09-10 05:36:09 more
  • Python 資料驅動工具:DDT

    背景 python 的unittest 沒有自帶資料驅動功能。 所以如果使用unittest,同時又想使用資料驅動,那么就可以使用DDT來完成。 DDT是 “Data-Driven Tests”的縮寫。 資料:http://ddt.readthedocs.io/en/latest/ 使用方法 dd. ......

    uj5u.com 2020-09-10 05:36:13 more
  • Python里面的xlrd模塊詳解

    那我就一下面積個問題對xlrd模塊進行學習一下: 1.什么是xlrd模塊? 2.為什么使用xlrd模塊? 3.怎樣使用xlrd模塊? 1.什么是xlrd模塊? ?python操作excel主要用到xlrd和xlwt這兩個庫,即xlrd是讀excel,xlwt是寫excel的庫。 今天就先來說一下xl ......

    uj5u.com 2020-09-10 05:36:28 more
  • 當我們創建HashMap時,底層到底做了什么?

    jdk1.7中的底層實作程序(底層基于陣列+鏈表) 在我們new HashMap()時,底層創建了默認長度為16的一維陣列Entry[ ] table。當我們呼叫map.put(key1,value1)方法向HashMap里添加資料的時候: 首先,呼叫key1所在類的hashCode()計算key1 ......

    uj5u.com 2020-09-10 05:36:38 more
最新发布
  • 【原型設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    簡介 原型模式(Prototype Pattern)是一種創建型設計模式,使你能夠復制已有物件,而無需使代碼依賴它們所屬的類,同時又能保證性能。 這種模式是實作了一個原型介面,該介面用于創建當前物件的克隆。當直接創建物件的代價比較大時,則采用這種模式。 如果你需要復制一些物件,同時又希望代碼獨立于這 ......

    uj5u.com 2023-04-24 10:25:37 more
  • 四大常用MQ的優缺點和應用場景選擇

    一、優缺點 ActiveMQ 官網地址:http://activemq.apache.org/ - 官網介紹 Apache ActiveMQ是最流行的開源、多協議、基于Java的訊息代理。它支持行業標準協議,因此用戶可以從多種語言和平臺的客戶端選擇中獲益。從JavaScript、C、C++、Pyth ......

    uj5u.com 2023-04-23 07:53:02 more
  • 四大常用MQ的優缺點和應用場景選擇

    一、優缺點 ActiveMQ 官網地址:http://activemq.apache.org/ - 官網介紹 Apache ActiveMQ是最流行的開源、多協議、基于Java的訊息代理。它支持行業標準協議,因此用戶可以從多種語言和平臺的客戶端選擇中獲益。從JavaScript、C、C++、Pyth ......

    uj5u.com 2023-04-23 07:52:29 more
  • 【觀察者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    簡介 觀察者模式(Observer Pattern)是一種行為型模式。它定義物件間的一種一對多的依賴關系,當一個物件的狀態發生改變時,所有依賴于它的物件都得到通知并被自動更新。 觀察者模式使用三個類Subject、Observer和Client。Subject物件帶有系結觀察者到Client物件和從 ......

    uj5u.com 2023-04-22 08:03:33 more
  • 【觀察者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    簡介 觀察者模式(Observer Pattern)是一種行為型模式。它定義物件間的一種一對多的依賴關系,當一個物件的狀態發生改變時,所有依賴于它的物件都得到通知并被自動更新。 觀察者模式使用三個類Subject、Observer和Client。Subject物件帶有系結觀察者到Client物件和從 ......

    uj5u.com 2023-04-22 08:03:16 more
  • 【備忘錄設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    簡介 備忘錄模式(Memento Pattern)是一種結構型設計模式。這種模式就是在不破壞封裝的條件下,將一個物件的狀態捕捉(Capture)住,并放在外部存盤起來,從而可以在將來合適的時候把這個物件還原到存盤起來的狀態。備忘錄模式常常與命令模式和迭代子模式一同使用。 備忘錄模式的角色有三個:備忘 ......

    uj5u.com 2023-04-21 08:29:20 more
  • 一種面向后端的微服務低代碼平臺架構設計

    結合京東業務研發實際情況,針對后端研發人員,設計一個微服務低代碼平臺,助力更高效低交付業務需求。現已結業,將我在本次專案中沉淀設計出的設計檔案整理成文,期待與大家有進一步的碰撞溝通 ......

    uj5u.com 2023-04-21 08:28:53 more
  • 【備忘錄設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    簡介 備忘錄模式(Memento Pattern)是一種結構型設計模式。這種模式就是在不破壞封裝的條件下,將一個物件的狀態捕捉(Capture)住,并放在外部存盤起來,從而可以在將來合適的時候把這個物件還原到存盤起來的狀態。備忘錄模式常常與命令模式和迭代子模式一同使用。 備忘錄模式的角色有三個:備忘 ......

    uj5u.com 2023-04-21 08:28:25 more
  • 一種面向后端的微服務低代碼平臺架構設計

    結合京東業務研發實際情況,針對后端研發人員,設計一個微服務低代碼平臺,助力更高效低交付業務需求。現已結業,將我在本次專案中沉淀設計出的設計檔案整理成文,期待與大家有進一步的碰撞溝通 ......

    uj5u.com 2023-04-21 08:27:42 more
  • 【中介者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    * 中介者模式是一種行為型設計模式,它可以用來減少類之間的直接依賴關系,
    * 將物件之間的通信封裝到一個中介者物件中,從而使得各個物件之間的關系更加松散。
    * 在中介者模式中,物件之間不再直接相互互動,而是通過中介者來中轉訊息。 ......

    uj5u.com 2023-04-20 08:20:47 more