当前位置:网站首页>Builder pattern
Builder pattern
2022-06-25 11:25:00 【tlqwanttolearnit】
Builder pattern (Builder Pattern) Also called generator mode , It's a bit like the factory model , Both use special classes to create objects .
- The factory pattern is used to create a series of related but different objects .
- The builder pattern is used to create a type of complex object , By setting different optional parameters , Customize to create different objects .
The main difference is that the builder pattern focuses on building a complex object step by step , And the abstract factory pattern focuses on multiple series of product objects .
Why use builder mode
- A class has many properties , Constructor and arguments are too long .
- There are certain dependencies and constraints between attributes .
- The creation of objects needs to follow a certain sequence or steps
There is a sentence that sums up the builder model very well :
When we want to create an object composed of multiple parts , And their construction needs to be done step by step , Only when all parts are created , This object is complete .
That's exactly what it is. Where the builder's design pattern can be used .
The advantages and disadvantages of the builder model
advantage
- Independence of builders , Easy to expand .
- Easy to control detail risk .
- Decouple the construction and presentation of objects
shortcoming
- Products must have something in common , The scope is limited .
- If the internal changes are complex , There will be a lot of construction classes .
The composition of the builder model
- The actual object : The actual object to return
- Builder abstract class : Define the functions that the builder entity class needs to implement .
- Builder entity class : Inherit builder abstract class , Concrete implementation of abstract class methods .
- Director class :
边栏推荐
- Coscon'22 lecturer solicitation order
- 开源社邀请您参加OpenSSF开源安全线上研讨会
- 金太阳教育美股上市:市值3.6亿美元 成小盘中概股
- Remove the problem of orange border on the desktop control in WebView
- 手机上股票开户安全吗?找谁可以开户啊?
- Handler、Message、Looper、MessageQueue
- Jincang KFS data cascade scenario deployment
- 10.1. Oracle constraint deferred, not deferred, initially deferred and initially deferred
- SQL注入漏洞(繞過篇)
- Jincang database kingbasees plug-in force_ view
猜你喜欢
记一次有趣的逻辑SRC挖掘
Jincang KFS data cascade scenario deployment
C disk uses 100% cleaning method
Shichuang energy rushes to the scientific innovation board: it plans to raise 1.1 billion yuan, with an annual revenue of 700million yuan and a 36% decrease in net profit
zabbix分布式系统监控
Shen Lu, China Communications Institute: police open source Protocol - ofl v1.1 Introduction and Compliance Analysis
Vulnérabilité à l'injection SQL (contournement)
基於Minifilter框架的雙緩沖透明加解密驅動 課程論文+項目源碼
Dragon Book tiger Book whale Book gnawing? Try the monkey book with Douban score of 9.5
A difficult mathematical problem baffles two mathematicians
随机推荐
金仓数据库 KingbaseES 插件DBMS_UTILITY
牛客网:旋转数组
Getting started with Apache Shenyu
How to realize the rich text editor function of mobile terminal
Shen Lu, China Communications Institute: police open source Protocol - ofl v1.1 Introduction and Compliance Analysis
How PHP extracts image addresses from strings
Very important very important very important very important very important very important very important very important very important
Explanation and use of kotlin syntax for Android
金仓数据库 KingbaseES 插件identity_pwdexp
Simple use of SVN
开源社邀请您参加OpenSSF开源安全线上研讨会
[file inclusion vulnerability-04] classic interview question: how to getshell when a website is known to have only local file inclusion vulnerability?
Crawler scheduling framework of scratch+scratch+grammar
PHP如何提取字符串中的图片地址
杭州/北京内推 | 阿里达摩院招聘视觉生成方向学术实习生(人才计划)
Is it safe to open a securities account in changtou school by mobile phone?
SystemVerilog (XIII) - enumerate data types
Detailed explanation of spark specification
Spark tuning tool -- detailed explanation of sparklens
中國信通院沈瀅:字體開源協議——OFL V1.1介紹及合規要點分析