Skip to content

Commit e6a7995

Browse files
author
142vip.cn
committed
feat: 大幅新增设计模式、Linux命令、ORM框架教程文档
1 parent 2cf3a53 commit e6a7995

File tree

201 files changed

+13699
-626
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+13699
-626
lines changed

README.md

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Nuxt.js是在vue框架上进行封装的,主要是用来解决单体页面的
143143

144144
## 后端【Node】
145145

146-
### Express框架
146+
### [Express框架](https://www.expressjs.com.cn/)
147147

148148
- [ ] [框架概念简介]()
149149
- [ ] [brew和tree的安装]()
@@ -240,11 +240,11 @@ Nuxt.js是在vue框架上进行封装的,主要是用来解决单体页面的
240240
- [ ] 简单使用
241241
- [ ] Node下的CURD操作、
242242

243-
### 算法
243+
## 算法
244244

245-
- [ ] 算法分析——时间、空间复杂度
245+
- [ ] 算法时间、空间复杂度分析
246246

247-
#### 查找算法
247+
### 查找算法
248248

249249
- [ ] 顺序查找
250250
- [ ] 折半查找
@@ -253,14 +253,74 @@ Nuxt.js是在vue框架上进行封装的,主要是用来解决单体页面的
253253
- [ ] 散列(Hash)表
254254
- [ ] 字符串模式匹配(KPM)
255255

256-
#### 排序算法
256+
### 排序算法
257257

258258
- [ ] 插入排序
259259
- [ ] 交换排序
260260
- [ ] 选择排序
261261
- [ ] 归并排序
262262
- [ ] 基数排序
263263

264+
## 设计模式
265+
266+
> 弥补编程语言缺陷
267+
268+
### 架构型模式
269+
270+
- [ ] [MVC模式]()
271+
- [ ] [MVP模式]()
272+
- [ ] [MVVM模式]()
273+
- [ ] [Widget模式]()
274+
- [ ] [简单工厂模式]()
275+
- [ ] [异步模块模式]()
276+
- [ ] [同步模块模式]()
277+
278+
### 技巧型模式
279+
280+
- [ ] [链模式]()
281+
- [ ] [委托模式]()
282+
- [ ] [惰性模式]()
283+
- [ ] [防抖模式]()
284+
- [ ] [节流模式]()
285+
- [ ] [参与者模式]()
286+
- [ ] [等待者模式]()
287+
- [ ] [简单模板模式]()
288+
- [ ] [数据访问对象模式]()
289+
290+
### 23种经典模式
291+
292+
#### 创建型模式(5种)
293+
294+
- [ ] [建造者(Builder)模式]()
295+
- [ ] [单例(Singleton)模式]()
296+
- [ ] [原型(Prototype)模式]()
297+
- [ ] [工厂方法(FactoryMethod)模式]()
298+
- [ ] [抽象工厂(AbstractFactory)模式]()
299+
300+
#### 结构型模式(7种)
301+
302+
- [ ] [代理(Proxy)模式]()
303+
- [ ] [桥接(Bridge)模式]()
304+
- [ ] [外观(Facade)模式]()
305+
- [ ] [适配器(Adapter)模式]()
306+
- [ ] [装饰(Decorator)模式]()
307+
- [ ] [享元(Flyweight)模式]()
308+
- [ ] [组合(Composite)模式]()
309+
310+
#### 行为型模式(11种)
311+
312+
- [ ] [状态(State)模式]()
313+
- [ ] [命令(Command)模式]()
314+
- [ ] [策略(Strategy)模式]()
315+
- [ ] [备忘录(Memento)模式]()
316+
- [ ] [访问者(Visitor)模式]()
317+
- [ ] [中介者(Mediator)模式]()
318+
- [ ] [迭代器(Iterator)模式]()
319+
- [ ] [观察者(Observer)模式]()
320+
- [ ] [解释器(Interpreter)模式]()
321+
- [ ] [模板方法(Template Method)模式]()
322+
- [ ] [职责链(Chain of Responsibility)模式]()
323+
264324
## 开发技巧
265325

266326
### 代码管理

code/algorithm/straightInsertSort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
/**
3-
* ++i 和 i++ 的区别: https://zhidao.baidu.com/question/40433825.html
3+
* ++i 和 i++ 的区别: https://zhidao.baidu.com/question/40433825.html
44
*/
55

66
function straightInsertSort(arr, len) {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* MVC模式
3+
* - ts版本
4+
*/
5+
namespace MVCPattern {
6+
7+
// 模型(Model)
8+
interface Todo {
9+
id: number;
10+
title: string;
11+
completed: boolean;
12+
}
13+
14+
class TodoModel {
15+
private todos: Todo[] = []
16+
17+
addTodo(todo: Todo) {
18+
this.todos.push(todo)
19+
}
20+
21+
getTodos() {
22+
return this.todos
23+
}
24+
25+
updateTodoStatus(id: number, completed: boolean) {
26+
const todo = this.todos.find((todo) => todo.id === id)
27+
if (todo) {
28+
todo.completed = completed
29+
}
30+
}
31+
}
32+
33+
// 视图(View)
34+
class TodoView {
35+
render(todos: Todo[]) {
36+
console.log('Todo List:')
37+
todos.forEach((todo) => {
38+
console.log(`[${todo.completed ? 'x' : ' '}] ${todo.title}`)
39+
})
40+
}
41+
}
42+
43+
// 控制器(Controller)
44+
class TodoController {
45+
private model: TodoModel
46+
private view: TodoView
47+
48+
constructor(model: TodoModel, view: TodoView) {
49+
this.model = model
50+
this.view = view
51+
}
52+
53+
addTodoToModel(todo: Todo) {
54+
this.model.addTodo(todo)
55+
}
56+
57+
updateTodoStatusInModel(id: number, completed: boolean) {
58+
this.model.updateTodoStatus(id, completed)
59+
}
60+
61+
updateView() {
62+
const todos = this.model.getTodos()
63+
this.view.render(todos)
64+
}
65+
}
66+
67+
// 使用示例
68+
const model = new TodoModel()
69+
const view = new TodoView()
70+
const controller = new TodoController(model, view)
71+
72+
// 添加新任务
73+
const todo1: Todo = { id: 1, title: 'Learn TypeScript', completed: false }
74+
const todo2: Todo = { id: 2, title: 'Write Code', completed: true }
75+
76+
controller.addTodoToModel(todo1)
77+
controller.addTodoToModel(todo2)
78+
79+
// 更新任务状态
80+
controller.updateTodoStatusInModel(1, true)
81+
82+
// 更新视图
83+
controller.updateView()
84+
}

code/design-patterns/crp-demo.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* 合成复用原则Demo
3+
*/
4+
namespace CrpDemo {
5+
interface Logger {
6+
log(message: string): void;
7+
}
8+
9+
class ConsoleLogger implements Logger {
10+
log(message: string): void {
11+
console.log(`[ConsoleLogger] ${message}`)
12+
}
13+
}
14+
15+
class FileLogger implements Logger {
16+
log(message: string): void {
17+
console.log(`[FileLogger] ${message}`)
18+
// 将日志写入文件的具体实现
19+
}
20+
}
21+
22+
class User {
23+
private logger: Logger
24+
25+
constructor(logger: Logger) {
26+
this.logger = logger
27+
}
28+
29+
save(): void {
30+
// 执行保存用户的逻辑
31+
this.logger.log('User saved.')
32+
}
33+
}
34+
35+
// 使用示例
36+
const consoleLogger = new ConsoleLogger()
37+
const userWithConsoleLogger = new User(consoleLogger)
38+
userWithConsoleLogger.save()
39+
40+
const fileLogger = new FileLogger()
41+
const userWithFileLogger = new User(fileLogger)
42+
userWithFileLogger.save()
43+
}

code/design-patterns/dip-demo.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* 依赖倒置原则Demo
3+
*/
4+
namespace DipDemo {
5+
interface IMessageSender {
6+
sendMessage(message: string): void;
7+
}
8+
9+
class EmailSender implements IMessageSender {
10+
sendMessage(message: string): void {
11+
console.log(`Sending email: ${message}`)
12+
}
13+
}
14+
15+
class SMSMessageSender implements IMessageSender {
16+
sendMessage(message: string): void {
17+
console.log(`Sending SMS: ${message}`)
18+
}
19+
}
20+
21+
class NotificationService {
22+
private messageSender: IMessageSender
23+
24+
constructor(messageSender: IMessageSender) {
25+
this.messageSender = messageSender
26+
}
27+
28+
sendNotification(message: string): void {
29+
this.messageSender.sendMessage(message)
30+
}
31+
}
32+
33+
// 使用示例
34+
const emailSender = new EmailSender()
35+
const smsSender = new SMSMessageSender()
36+
37+
const emailNotification = new NotificationService(emailSender)
38+
const smsNotification = new NotificationService(smsSender)
39+
40+
emailNotification.sendNotification('Hello, email notification.')
41+
smsNotification.sendNotification('Hello, SMS notification.')
42+
}

code/design-patterns/isp-demo.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* 接口隔离原则Demo
3+
*/
4+
namespace IspDemo {
5+
interface Animal {
6+
eat(): void;
7+
}
8+
9+
interface Flyable {
10+
fly(): void;
11+
}
12+
13+
class Bird implements Animal, Flyable {
14+
public eat(): void {
15+
console.log('Bird is eating...')
16+
}
17+
18+
public fly(): void {
19+
console.log('Bird is flying...')
20+
}
21+
}
22+
23+
class Dog implements Animal {
24+
public eat(): void {
25+
console.log('Dog is eating...')
26+
}
27+
}
28+
29+
// 使用示例
30+
const bird = new Bird()
31+
bird.eat()
32+
bird.fly()
33+
34+
const dog = new Dog()
35+
dog.eat()
36+
}

code/design-patterns/lod-demo.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* 迪米特法则Demo
3+
* 又叫最小知道原则
4+
*/
5+
namespace LodDemo {
6+
class Person {
7+
private readonly name: string
8+
9+
constructor(name: string) {
10+
this.name = name
11+
}
12+
13+
getName(): string {
14+
return this.name
15+
}
16+
}
17+
18+
class Team {
19+
private readonly members: Person[]
20+
21+
constructor() {
22+
this.members = []
23+
}
24+
25+
addMember(member: Person): void {
26+
this.members.push(member)
27+
}
28+
29+
printTeamMembers(): void {
30+
for (const member of this.members) {
31+
console.log(member.getName())
32+
}
33+
}
34+
}
35+
36+
// 使用示例
37+
const john = new Person('John')
38+
const jane = new Person('Jane')
39+
const team = new Team()
40+
41+
team.addMember(john)
42+
team.addMember(jane)
43+
44+
team.printTeamMembers()
45+
}

0 commit comments

Comments
 (0)