Skip to content

Commit

Permalink
feat: 大幅新增设计模式、Linux命令、ORM框架教程文档
Browse files Browse the repository at this point in the history
  • Loading branch information
142vip.cn committed Nov 28, 2023
1 parent 2cf3a53 commit e6a7995
Show file tree
Hide file tree
Showing 201 changed files with 13,699 additions and 626 deletions.
70 changes: 65 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Nuxt.js是在vue框架上进行封装的,主要是用来解决单体页面的

## 后端【Node】

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

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

### 算法
## 算法

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

#### 查找算法
### 查找算法

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

#### 排序算法
### 排序算法

- [ ] 插入排序
- [ ] 交换排序
- [ ] 选择排序
- [ ] 归并排序
- [ ] 基数排序

## 设计模式

> 弥补编程语言缺陷
### 架构型模式

- [ ] [MVC模式]()
- [ ] [MVP模式]()
- [ ] [MVVM模式]()
- [ ] [Widget模式]()
- [ ] [简单工厂模式]()
- [ ] [异步模块模式]()
- [ ] [同步模块模式]()

### 技巧型模式

- [ ] [链模式]()
- [ ] [委托模式]()
- [ ] [惰性模式]()
- [ ] [防抖模式]()
- [ ] [节流模式]()
- [ ] [参与者模式]()
- [ ] [等待者模式]()
- [ ] [简单模板模式]()
- [ ] [数据访问对象模式]()

### 23种经典模式

#### 创建型模式(5种)

- [ ] [建造者(Builder)模式]()
- [ ] [单例(Singleton)模式]()
- [ ] [原型(Prototype)模式]()
- [ ] [工厂方法(FactoryMethod)模式]()
- [ ] [抽象工厂(AbstractFactory)模式]()

#### 结构型模式(7种)

- [ ] [代理(Proxy)模式]()
- [ ] [桥接(Bridge)模式]()
- [ ] [外观(Facade)模式]()
- [ ] [适配器(Adapter)模式]()
- [ ] [装饰(Decorator)模式]()
- [ ] [享元(Flyweight)模式]()
- [ ] [组合(Composite)模式]()

#### 行为型模式(11种)

- [ ] [状态(State)模式]()
- [ ] [命令(Command)模式]()
- [ ] [策略(Strategy)模式]()
- [ ] [备忘录(Memento)模式]()
- [ ] [访问者(Visitor)模式]()
- [ ] [中介者(Mediator)模式]()
- [ ] [迭代器(Iterator)模式]()
- [ ] [观察者(Observer)模式]()
- [ ] [解释器(Interpreter)模式]()
- [ ] [模板方法(Template Method)模式]()
- [ ] [职责链(Chain of Responsibility)模式]()

## 开发技巧

### 代码管理
Expand Down
2 changes: 1 addition & 1 deletion code/algorithm/straightInsertSort.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/**
* ++i 和 i++ 的区别: https://zhidao.baidu.com/question/40433825.html
* ++i 和 i++ 的区别: https://zhidao.baidu.com/question/40433825.html
*/

function straightInsertSort(arr, len) {
Expand Down
84 changes: 84 additions & 0 deletions code/design-patterns/MVC模式/MVCPattern.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* MVC模式
* - ts版本
*/
namespace MVCPattern {

// 模型(Model)
interface Todo {
id: number;
title: string;
completed: boolean;
}

class TodoModel {
private todos: Todo[] = []

addTodo(todo: Todo) {
this.todos.push(todo)
}

getTodos() {
return this.todos
}

updateTodoStatus(id: number, completed: boolean) {
const todo = this.todos.find((todo) => todo.id === id)
if (todo) {
todo.completed = completed
}
}
}

// 视图(View)
class TodoView {
render(todos: Todo[]) {
console.log('Todo List:')
todos.forEach((todo) => {
console.log(`[${todo.completed ? 'x' : ' '}] ${todo.title}`)
})
}
}

// 控制器(Controller)
class TodoController {
private model: TodoModel
private view: TodoView

constructor(model: TodoModel, view: TodoView) {
this.model = model
this.view = view
}

addTodoToModel(todo: Todo) {
this.model.addTodo(todo)
}

updateTodoStatusInModel(id: number, completed: boolean) {
this.model.updateTodoStatus(id, completed)
}

updateView() {
const todos = this.model.getTodos()
this.view.render(todos)
}
}

// 使用示例
const model = new TodoModel()
const view = new TodoView()
const controller = new TodoController(model, view)

// 添加新任务
const todo1: Todo = { id: 1, title: 'Learn TypeScript', completed: false }
const todo2: Todo = { id: 2, title: 'Write Code', completed: true }

controller.addTodoToModel(todo1)
controller.addTodoToModel(todo2)

// 更新任务状态
controller.updateTodoStatusInModel(1, true)

// 更新视图
controller.updateView()
}
43 changes: 43 additions & 0 deletions code/design-patterns/crp-demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* 合成复用原则Demo
*/
namespace CrpDemo {
interface Logger {
log(message: string): void;
}

class ConsoleLogger implements Logger {
log(message: string): void {
console.log(`[ConsoleLogger] ${message}`)
}
}

class FileLogger implements Logger {
log(message: string): void {
console.log(`[FileLogger] ${message}`)
// 将日志写入文件的具体实现
}
}

class User {
private logger: Logger

constructor(logger: Logger) {
this.logger = logger
}

save(): void {
// 执行保存用户的逻辑
this.logger.log('User saved.')
}
}

// 使用示例
const consoleLogger = new ConsoleLogger()
const userWithConsoleLogger = new User(consoleLogger)
userWithConsoleLogger.save()

const fileLogger = new FileLogger()
const userWithFileLogger = new User(fileLogger)
userWithFileLogger.save()
}
42 changes: 42 additions & 0 deletions code/design-patterns/dip-demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* 依赖倒置原则Demo
*/
namespace DipDemo {
interface IMessageSender {
sendMessage(message: string): void;
}

class EmailSender implements IMessageSender {
sendMessage(message: string): void {
console.log(`Sending email: ${message}`)
}
}

class SMSMessageSender implements IMessageSender {
sendMessage(message: string): void {
console.log(`Sending SMS: ${message}`)
}
}

class NotificationService {
private messageSender: IMessageSender

constructor(messageSender: IMessageSender) {
this.messageSender = messageSender
}

sendNotification(message: string): void {
this.messageSender.sendMessage(message)
}
}

// 使用示例
const emailSender = new EmailSender()
const smsSender = new SMSMessageSender()

const emailNotification = new NotificationService(emailSender)
const smsNotification = new NotificationService(smsSender)

emailNotification.sendNotification('Hello, email notification.')
smsNotification.sendNotification('Hello, SMS notification.')
}
36 changes: 36 additions & 0 deletions code/design-patterns/isp-demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* 接口隔离原则Demo
*/
namespace IspDemo {
interface Animal {
eat(): void;
}

interface Flyable {
fly(): void;
}

class Bird implements Animal, Flyable {
public eat(): void {
console.log('Bird is eating...')
}

public fly(): void {
console.log('Bird is flying...')
}
}

class Dog implements Animal {
public eat(): void {
console.log('Dog is eating...')
}
}

// 使用示例
const bird = new Bird()
bird.eat()
bird.fly()

const dog = new Dog()
dog.eat()
}
45 changes: 45 additions & 0 deletions code/design-patterns/lod-demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* 迪米特法则Demo
* 又叫最小知道原则
*/
namespace LodDemo {
class Person {
private readonly name: string

constructor(name: string) {
this.name = name
}

getName(): string {
return this.name
}
}

class Team {
private readonly members: Person[]

constructor() {
this.members = []
}

addMember(member: Person): void {
this.members.push(member)
}

printTeamMembers(): void {
for (const member of this.members) {
console.log(member.getName())
}
}
}

// 使用示例
const john = new Person('John')
const jane = new Person('Jane')
const team = new Team()

team.addMember(john)
team.addMember(jane)

team.printTeamMembers()
}

0 comments on commit e6a7995

Please sign in to comment.