惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
Martin Fowler
Martin Fowler
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
博客园_首页
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
MongoDB | Blog
MongoDB | Blog
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
雷峰网
雷峰网
D
Docker
博客园 - 司徒正美
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
U
Unit 42
J
Java Code Geeks
A
About on SuperTechFans
N
Netflix TechBlog - Medium
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security Affairs
I
Intezer
Cisco Talos Blog
Cisco Talos Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
B
Blog RSS Feed
P
Privacy & Cybersecurity Law Blog
T
Tenable Blog
T
Threatpost
H
Hacker News: Front Page
G
Google Developers Blog
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
L
Lohrmann on Cybersecurity
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
A
Arctic Wolf
S
Secure Thoughts
GbyAI
GbyAI
NISL@THU
NISL@THU
S
Security @ Cisco Blogs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Webroot Blog
Webroot Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
O
OpenAI News
Spread Privacy
Spread Privacy
Application and Cybersecurity Blog
Application and Cybersecurity Blog

ccagml

使用valgrind观察luajit进程内存 - ccagml 从生产环境报错学习protobuf编码规则 - ccagml 拨开迷雾,探寻深夜游戏集群启动失败真相 - ccagml 从技能状态图标显示错误到给 LuaJIT 报告bug - ccagml 游戏系统MySQl执行超时问题排查 - ccagml lua中pairs和ipairs都做了什么操作 - ccagml lua中#号是怎么计算字符串长度的 - ccagml lua中#号是怎么计算长度的 - ccagml lua中tonumber做了什么 - ccagml
跟着vscode插件学设计模式-工厂模式 - ccagml
2022-11-20 · via ccagml

项目地址

项目背景

leetcode_extension项目是一个Visual Studio Code插件,在插件市场也有发布

工厂模式相关概念

  • 创建型模式
  • 主要解决:解决接口选择问题
  • 如何解决:让其子类实现工厂接口,返回的也是一个抽象的产品。
  • 优点:
    1. 根据字符串名称创建对象
    2. 扩展性高,如果想增加一个子类功能,只要扩展一个工厂类就可以。
    3. 屏蔽产品的具体实现,调用者只关心可使用的接口。
  • 缺点:
    1. 每增加一个功能,都需要改动增加一个具体的子类和对象实现工厂。
    2. 类的数量变多,复杂度上升,系统对具体类的依赖

项目中的代码

  1. 调用入口
    • src/rpc/childMain.ts
          let curApi: IApi | undefined = apiFactory.getApi(com_str);
          curApi?.call(curApi?.callArg(process.argv));
      
    • 这里根据com_str一个字符串名称,从apiFactory中获取对应的api子类对象,并执行api的接口call
  2. apiFactory的实现
    • src/rpc/factory/apiFactory.ts
      import { cacheApi } from "./api/cacheApi";
      import { pluginApi } from "./api/pluginApi";
      '''
      '''
      import { IApi } from "./apiBase";
      
      class ApiFactory {
      constructor() {}
      getApi(api: string): IApi | undefined {
          if (api == "cache") {
          return cacheApi;
          } else if (api == "plugin") {
          return pluginApi;
          }
          }
          return undefined;
      }
      }
      export const apiFactory: ApiFactory = new ApiFactory();
      
      
      • 根据字符串创建对应的api功能类
      • 所有api功能类都继承自apiBase
  3. 所有api的基类
    • src/rpc/factory/apiBase.ts
      export interface IApi {
          callArg(arg);
          call(arg): void;
      }
      
      export class ApiBase implements IApi {
          constructor() {}
          callArg(arg: any) {
              console.log("未实现callArg", arg);
          }
          call(arg: any) {
              console.log("未实现call", arg);
          }
          api_argv() {
              console.log("未实现api_argv", arg);
          }
      }