对面向对象编程原则和设计模式

对面向对象编程原则和设计模式有扎实的理解 招聘要求中提到的**“对面向对象编程原则和设计模式有扎实的理解”,指的是能够编写出高内聚、低耦合、易扩展、易维护**的代码,而不是简单地把代码堆砌在几个类里。 这主要包含 面向对象三大特性、SOLID 五大设计原则 以及 常用设计模式 3 个层面的具体能力。 1. 面向对象三大特性(基础) 封装 (Encapsulation): 隐藏内部实现细节,仅暴露必要的接口(利用 private / public / protected 保护数据)。 继承 (Inheritance): 提取代码复用,建立 “is-a” 的层级关系(警惕过度继承,优先考虑组合)。 多态 (Polymorphism): 基于抽象(接口或抽象类)编写代码,运行时动态绑定具体实现。 2. SOLID 设计原则(核心) 原则 名称 核心思想 反面教材 vs 正确做法 S 单一职责原则 (SRP) 一个类应该只有一个发生变化的原因。 反面:一个 UserService 既处理业务逻辑,又直接拼 SQL 发送邮件。正确:拆分为 UserService、UserRepository、EmailService。 O 开闭原则 (OCP) 对扩展开放,对修改关闭。 扩展新功能时,尽量通过添加新类来实现,而不是修改原有代码。 L 里氏替换原则 (LSP) 子类必须能够替换掉它们的父类(或接口)。 不要在子类重写方法时直接 throw new NotImplementedException()。 I 接口隔离原则 (ISP) 客户端不应该依赖它不需要的接口。 避免定义庞大的“万能接口”,将其拆分为多个职责明确的小接口。 D 依赖倒置原则 (DIP) 高层模块不应该依赖低层模块,二者都应该依赖于抽象。 依赖于 INotificationService 接口,而不是具体的 SmsService 类(配合依赖注入 DI)。 3....

2026-09-08 · 2 分钟 · SAM

使用openvpn搭建中国服务器

第一步:创建并编辑脚本文件 在 Ubuntu 终端中执行以下命令,创建一个名为 setup_vpn.sh 的文件: 1 nano setup_vpn.sh 第二步:复制完整脚本代码 在打开的编辑器中,粘贴以下全自动脚本代码(代码中已自动处理交互确认,无需手动按回车或输入 yes): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 #!...

2026-08-30 · 3 分钟 · SAM

VPS 使用 Xray 搭建 VLESS+Reality 节点

安装 xray bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install 生成 uuid xray uuid 输出示例:8653f110-61d8-4363-8c5c-1224fa1bc18b 生成 Reality 密钥对 # 生成 X25519 公私钥对 xray x25519 输出示例: PrivateKey: CDQnBSjLb45viCBJTVt7n5ZmImy80NW7ovdlqRPi2k Password (PublicKey): nZY-gSIXu1N6lxpxzodqf_hc08UQBEkqiLNN5hv8TQ Hash32: VXqfOosY-X1NwQTfMx7Vfd3kxlRvvxJYM5Vrac9WNJU **重要:请保存好这两个密钥!** - Private key(私钥):配置在服务器端 - Password(原 Public Key -> 公钥):配置在客户端 生成 Short ID # 生成 16 位十六进制 short_id openssl rand -hex 8 输出示例:a7c581a4431eca74 编辑 Xray 配置文件 vim /usr/local/etc/xray/config.json 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 { "log": { "loglevel": "info" }, "inbounds": [ { "tag": "VLESS-Vision-REALITY", "listen": "::", "port": 443, "protocol": "vless", "settings": { "clients": [ { "id": "8653f110-61d8-4363-8c5c-1224fa1bc18b", // 填入刚才生成的 UUID "flow": "xtls-rprx-vision" } ], "decryption": "none" }, "streamSettings": { "network": "raw", "security": "reality", "realitySettings": { "show": false, "dest": "www....

2026-05-05 · 3 分钟 · SAM

Trojan服务配置

前提条件: 一台外网云服务器 域名 https 证书 服务端安装 trojan 切换到 root 身份:sudo su 1 bash -c "$(curl -fsSL https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh)" 安装提示: Entering temp directory /tmp/tmp.3t5aPoYDpj... Downloading trojan 1.16.0... ################################################################################################################################################### 100.0% Unpacking trojan 1.16.0... Installing trojan 1.16.0 to /usr/local/bin/trojan... Installing trojan server config to /usr/local/etc/trojan/config.json... Installing trojan systemd service to /etc/systemd/system/trojan.service... Reloading systemd daemon... Deleting temp directory /tmp/tmp.3t5aPoYDpj... Done! 配置文档说明:https://trojan-gfw.github.io/trojan/config 修改配置 server.json 服务器配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 { "run_type": "server", "local_addr": "0....

2025-07-31 · 2 分钟 · SAM

Caddy Config

使用 caddy 配置开发证书 新增 Caddyfile,增加以下内容: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 { log { output file D:\dev\caddy_server\logs\access.log format json } } myhost.com { tls internal reverse_proxy https://127.0.0.1:44325 { transport http { tls_insecure_skip_verify } } } 在 C:\Windows\System32\drivers\etc\hosts 增加一行:127.0.0.1 myhost.com

2025-07-27 · 1 分钟 · SAM

WinSW Nginx 配置

WinSW 配置 nginx 服务 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 <service> <id>nginx service</id> <name>Nginx</name> <description>Nginx服务.</description> <!-- 环境变量 --> <env name="NGINX_COMIC" value="%BASE%" /> <executable>%base%\nginx.exe</executable> <workingdirectory>%BASE%</workingdirectory> <arguments>-p %BASE%</arguments> <!-- 日志配置 --> <logpath>%BASE%\logs</logpath> <log mode="roll-by-size"> <sizeThreshold>10240</sizeThreshold> <keepFiles>8</keepFiles> </log> <!-- 启动模式 --> <startmode>Automatic</startmode> <delayedAutoStart>true</delayedAutoStart> <!...

2025-06-08 · 1 分钟 · SAM

Mysql Usage

显示当前进程列表 1 2 3 SHOW PROCESSLIST; SHOW full PROCESSLIST 显示最大链接数 1 show variables like '%max_connections%'; 当连接数不够用时,产生错误:Too many connections System.InvalidOperationException: An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding ‘EnableRetryOnFailure()’ to the ‘UseMySql’ call. —> MySqlConnector.MySqlException (0x80004005): Too many connections at MySqlConnector.Core.ServerSession.ReceiveReplyAsyncAwaited(ValueTask1 task) in /_/src/MySqlConnector/Core/ServerSession.cs:line 910 at MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, MySqlConnection connection, Int32 startTickCount, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ServerSession....

2024-11-07 · 4 分钟 · SAM

中间件 - ActiveMQ

安装 ActiveMQ 下载ActiveMQ压缩包 ActiveMQ 解压压缩包 进入 bin\win64 目录下执行 activemq.bat 启动成功后,访问 http://localhost:8161/admin/ 输入用户名密码 admin admin 即可登录 用户名密码保存在根目录 conf\jetty-realm.properties 文件中 .net Nuget 安装 ActiveMQ 1 Install-Package Apache.NMS.ActiveMQ Queue类似编程语言中的Queue,每条消息只会被一个消费者接收; Topic类似广播,发送的消息会被多个消费者接受,前提是订阅了该主题的消息。

2024-09-10 · 1 分钟 · SAM

Redis Dotnet

安装 StackExchange.Redis 1 Install-Package StackExchange.Redis Redis 开启键空间通知功能 打开 redis.conf 文件,找到 notify-keyspace-events 配置项,修改为 Ex,然后重启 redis 服务。 1 notify-keyspace-events "Ex" notify-keyspace-events 的参数可以是以下字符的任意组合,它指定了服务器该发送哪些类型的通知: 字符 发送的通知 K 键空间通知,所有通知以 keyspace@ 为前缀 E 键事件通知,所有通知以 keyevent@ 为前缀 g DEL 、 EXPIRE 、 RENAME 等类型无关的通用命令的通知 $ 字符串命令的通知 l 列表命令的通知 s 集合命令的通知 h 哈希命令的通知 z 有序集合命令的通知 x 过期事件,每当有过期键被删除时发送 e 驱逐事件,每当有键因为 maxmemory 政策而被删除时发送 A 参数 g$lshzxe 的别名 .net 订阅键过期事件 1 2 3 4 5 6 7 ConnectionMultiplexer _redis = ConnectionMultiplexer.Connect("127.0.0.1:6379");; var sub = _redis....

2024-09-05 · 1 分钟 · SAM

Golang Learn

go 导入包 1 2 3 4 5 6 7 8 import ( "encoding/json" "fmt" "os" "time" dbmodels "github.com/xxxx/g_hikapi/models" ) import : 导入包 "encoding/json" : 导入 json 包 "fmt" : 导入 fmt 包 "os" : 导入 os 包 "time" : 导入 time 包 dbmodels : 导入 dbmodels 包, dbmodels 为自定义包名或者别名 在调用包调用时,需要使用别名来调用包中的函数、变量、类型等。 go 生成 exe 1 2 $ go build -o HIK_SYNC.exe -ldflags="-w -s -X 'main.version=1.0.0'" $ upx -9 HIK_SYNC.exe go build : 编译程序 -o : 设置输出文件名 HIK_SYNC....

2024-08-26 · 1 分钟 · SAM