【JavaScript】面向对象与设计模式

在这里插入图片描述

个人主页:Guiat
归属专栏:HTML CSS JavaScript

在这里插入图片描述

文章目录

  • 1. JavaScript 中的面向对象编程
    • 1.1 对象基础
    • 1.2 构造函数
    • 1.3 原型和原型链
    • 1.4 ES6 类
    • 1.5 继承
    • 1.6 封装
  • 2. 创建型设计模式
    • 2.1 工厂模式
    • 2.2 单例模式
    • 2.3 建造者模式
    • 2.4 原型模式
  • 3. 结构型设计模式
    • 3.1 适配器模式
    • 3.2 装饰器模式
    • 3.3 代理模式
    • 3.4 组合模式
  • 4. 行为型设计模式
    • 4.1 观察者模式
    • 4.2 策略模式
    • 4.3 命令模式
    • 4.4 迭代器模式
    • 4.5 中介者模式
  • 5. 实际应用案例
    • 5.1 表单验证系统

正文

1. JavaScript 中的面向对象编程

1.1 对象基础

在 JavaScript 中,对象是键值对的集合,几乎所有事物都是对象。

// 对象字面量
const person = {name: 'John',age: 30,greet: function() {return `Hello, my name is ${this.name}`;}
};// 访问属性
console.log(person.name); // "John"
console.log(person['age']); // 30// 调用方法
console.log(person.greet()); // "Hello, my name is John"

1.2 构造函数

构造函数用于创建和初始化对象。

function Person(name, age) {this.name = name;this.age = age;this.greet = function() {return `Hello, my name is ${this.name}`;};
}// 使用 new 关键字创建实例
const john = new Person('John', 30);
const jane = new Person('Jane', 25);console.log(john.greet()); // "Hello, my name is John"
console.log(jane.greet()); // "Hello, my name is Jane"// 验证实例类型
console.log(john instanceof Person); // true

1.3 原型和原型链

每个 JavaScript 对象都连接到一个原型对象,可以从中继承属性和方法。

function Person(name, age) {this.name = name;this.age = age;
}// 在原型上添加方法
Person.prototype.greet = function() {return `Hello, my name is ${this.name}`;
};const john = new Person('John', 30);
const jane = new Person('Jane', 25);console.log(john.greet()); // "Hello, my name is John"
console.log(john.greet === jane.greet); // true - 方法共享// 原型链
console.log(john.__proto__ === Person.prototype); // true
console.log(Person.prototype.__proto__ === Object.prototype); // true
console.log(Object.prototype.__proto__); // null

1.4 ES6 类

ES6 引入了类语法,使面向对象编程更直观。

class Person {constructor(name, age) {this.name = name;this.age = age;}// 实例方法greet() {return `Hello, my name is ${this.name}`;}// 静态方法static createAnonymous() {return new Person('Anonymous', 0);}// getterget profile() {return `${this.name}, ${this.age} years old`;}// setterset profile(value) {[this.name, this.age] = value.split(',');this.age = parseInt(this.age, 10);}
}const john = new Person('John', 30);
console.log(john.greet()); // "Hello, my name is John"// 静态方法调用
const anonymous = Person.createAnonymous();
console.log(anonymous.name); // "Anonymous"

1.5 继承

继承允许一个类基于另一个类创建,共享和扩展其功能。

// ES5 继承
function Person(name, age) {this.name = name;this.age = age;
}Person.prototype.greet = function() {return `Hello, my name is ${this.name}`;
};function Employee(name, age, company) {// 调用父类构造函数Person.call(this, name, age);this.company = company;
}// 设置原型链
Employee.prototype = Object.create(Person.prototype);
Employee.prototype.constructor = Employee;// 添加新方法
Employee.prototype.work = function() {return `${this.name} works at ${this.company}`;
};// ES6 继承
class Person {constructor(name, age) {this.name = name;this.age = age;}greet() {return `Hello, my name is ${this.name}`;}
}class Employee extends Person {constructor(name, age, company) {super(name, age); // 调用父类构造函数this.company = company;}work() {return `${this.name} works at ${this.company}`;}// 覆盖父类方法greet() {return `${super.greet()} and I work at ${this.company}`;}
}const jane = new Employee('Jane', 25, 'Facebook');
console.log(jane.greet()); // "Hello, my name is Jane and I work at Facebook"

1.6 封装

封装是隐藏对象内部状态和实现细节的技术。

// 使用闭包实现私有变量
function Person(name, age) {// 私有变量let _name = name;let _age = age;// 公共接口this.getName = function() {return _name;};this.setName = function(name) {if (name.length > 0) {_name = name;}};
}// ES2022 私有字段和方法
class Person {// 私有字段#name;#age;constructor(name, age) {this.#name = name;this.#age = age;}// 公共方法getName() {return this.#name;}// 私有方法#validateAge(age) {return age > 0 && age < 120;}
}

2. 创建型设计模式

创建型设计模式关注对象的创建机制,以适合特定情况的方式创建对象。

2.1 工厂模式

工厂模式通过一个中央函数创建对象。

// 简单工厂
function createUser(type) {if (type === 'admin') {return {name: 'Admin User',permissions: ['read', 'write', 'delete']};} else if (type === 'user') {return {name: 'Regular User',permissions: ['read']};}
}const adminUser = createUser('admin');
console.log(adminUser.permissions); // ["read", "write", "delete"]// 工厂方法
class UserFactory {static createAdmin(name) {return {name,permissions: ['read', 'write', 'delete'],role: 'admin'};}static createRegular(name) {return {name,permissions: ['read'],role: 'user'};}
}const admin = UserFactory.createAdmin('John');
const user = UserFactory.createRegular('Jane');

2.2 单例模式

单例模式确保一个类只有一个实例,并提供一个全局访问点。

// 简单单例
const Singleton = (function() {let instance;function createInstance() {return {name: 'Singleton Instance',getData: function() {return this.name;}};}return {getInstance: function() {if (!instance) {instance = createInstance();}return instance;}};
})();const instance1 = Singleton.getInstance();
const instance2 = Singleton.getInstance();
console.log(instance1 === instance2); // true// ES6 单例
class Database {constructor(host, port) {if (Database.instance) {return Database.instance;}this.host = host;this.port = port;this.connected = false;Database.instance = this;}connect() {if (this.connected) {return this;}console.log(`Connecting to ${this.host}:${this.port}`);this.connected = true;return this;}
}const db1 = new Database('localhost', 3306).connect();
const db2 = new Database('example.com', 8080).connect();
console.log(db1 === db2); // true
console.log(db2.host); // "localhost" (不是 "example.com")

2.3 建造者模式

建造者模式将复杂对象的构建与其表示分离,使同一构建过程可创建不同表示。

// 建造者模式
class HouseBuilder {constructor() {this.house = {};}setBuildingType(buildingType) {this.house.buildingType = buildingType;return this;}setWallMaterial(wallMaterial) {this.house.wallMaterial = wallMaterial;return this;}setNumberOfDoors(number) {this.house.doors = number;return this;}setNumberOfWindows(number) {this.house.windows = number;return this;}build() {return this.house;}
}const house = new HouseBuilder().setBuildingType('apartment').setWallMaterial('brick').setNumberOfDoors(2).setNumberOfWindows(4).build();// 使用指挥者
class HouseDirector {buildCottage(builder) {return builder.setBuildingType('cottage').setWallMaterial('wood').setNumberOfDoors(2).setNumberOfWindows(8).build();}buildApartment(builder) {return builder.setBuildingType('apartment').setWallMaterial('concrete').setNumberOfDoors(1).setNumberOfWindows(4).build();}
}const director = new HouseDirector();
const cottage = director.buildCottage(new HouseBuilder());

2.4 原型模式

原型模式基于现有对象创建新对象,而不是从头构建。

// ES5 方式
const carPrototype = {init: function(make, model, year) {this.make = make;this.model = model;this.year = year;return this;},getInfo: function() {return `${this.make} ${this.model} (${this.year})`;}
};const car1 = Object.create(carPrototype).init('Toyota', 'Camry', 2020);
const car2 = Object.create(carPrototype).init('Honda', 'Accord', 2022);// 使用类
class Car {constructor(make, model, year) {this.make = make;this.model = model;this.year = year;}getInfo() {return `${this.make} ${this.model} (${this.year})`;}clone() {return new Car(this.make, this.model, this.year);}
}const tesla = new Car('Tesla', 'Model S', 2020);
const clonedTesla = tesla.clone();
clonedTesla.year = 2021;

3. 结构型设计模式

结构型设计模式关注类和对象的组合,形成更大的结构。

3.1 适配器模式

适配器模式使接口不兼容的类能一起工作。

// 旧接口
class OldCalculator {constructor() {this.operations = function(term1, term2, operation) {switch(operation) {case 'add':return term1 + term2;case 'sub':return term1 - term2;default:return NaN;}};}
}// 新接口
class NewCalculator {constructor() {this.add = function(term1, term2) {return term1 + term2;};this.sub = function(term1, term2) {return term1 - term2;};}
}// 适配器
class CalculatorAdapter {constructor() {const newCalc = new NewCalculator();this.operations = function(term1, term2, operation) {switch(operation) {case 'add':return newCalc.add(term1, term2);case 'sub':return newCalc.sub(term1, term2);default:return NaN;}};}
}// 客户端代码使用旧接口
const oldCalc = new OldCalculator();
console.log(oldCalc.operations(10, 5, 'add')); // 15// 适配新接口
const adaptedCalc = new CalculatorAdapter();
console.log(adaptedCalc.operations(10, 5, 'add')); // 15

3.2 装饰器模式

装饰器模式动态地向对象添加新功能,而不改变其原有结构。

// 基础组件
class Coffee {cost() {return 5;}description() {return 'Plain coffee';}
}// 装饰器
class MilkDecorator {constructor(coffee) {this.coffee = coffee;}cost() {return this.coffee.cost() + 1;}description() {return `${this.coffee.description()} with milk`;}
}class SugarDecorator {constructor(coffee) {this.coffee = coffee;}cost() {return this.coffee.cost() + 0.5;}description() {return `${this.coffee.description()} with sugar`;}
}// 使用
let coffee = new Coffee();
console.log(coffee.description()); // "Plain coffee"
console.log(coffee.cost()); // 5coffee = new MilkDecorator(coffee);
console.log(coffee.description()); // "Plain coffee with milk"
console.log(coffee.cost()); // 6coffee = new SugarDecorator(coffee);
console.log(coffee.description()); // "Plain coffee with milk with sugar"
console.log(coffee.cost()); // 6.5// JavaScript 装饰器(提案)
function readonly(target, name, descriptor) {descriptor.writable = false;return descriptor;
}class User {@readonlyusername() {return 'default';}
}

3.3 代理模式

代理模式为另一个对象提供替代或占位符,以控制对原始对象的访问。

// 真实主题
class RealImage {constructor(filename) {this.filename = filename;this.loadFromDisk();}loadFromDisk() {console.log(`Loading ${this.filename} from disk`);}display() {console.log(`Displaying ${this.filename}`);}
}// 代理
class ProxyImage {constructor(filename) {this.filename = filename;this.realImage = null;}display() {if (!this.realImage) {this.realImage = new RealImage(this.filename);}this.realImage.display();}
}// 客户端
const image = new ProxyImage('high-res-photo.jpg');
// 没有加载图像
console.log('Image object created');// 加载并显示图像
image.display();// 再次显示(不会重新加载)
image.display();

3.4 组合模式

组合模式将对象组合成树状结构,表示"部分-整体"层次结构。

// 组件接口
class UIComponent {constructor(name) {this.name = name;}render() {throw new Error('Render method must be implemented');}getComponentSize() {throw new Error('getComponentSize method must be implemented');}
}// 叶子组件
class Button extends UIComponent {constructor(name) {super(name);}render() {console.log(`Rendering Button: ${this.name}`);}getComponentSize() {return 1;}
}class Input extends UIComponent {constructor(name) {super(name);}render() {console.log(`Rendering Input: ${this.name}`);}getComponentSize() {return 1;}
}// 容器组件
class Form extends UIComponent {constructor(name) {super(name);this.components = [];}add(component) {this.components.push(component);}remove(component) {const index = this.components.indexOf(component);if (index !== -1) {this.components.splice(index, 1);}}render() {console.log(`Rendering Form: ${this.name}`);this.components.forEach(component => component.render());}getComponentSize() {return this.components.reduce((size, component) => {return size + component.getComponentSize();}, 0);}
}// 客户端代码
const loginForm = new Form('Login Form');
loginForm.add(new Input('Username'));
loginForm.add(new Input('Password'));
loginForm.add(new Button('Submit'));const registrationForm = new Form('Registration Form');
registrationForm.add(new Input('Name'));
registrationForm.add(new Input('Email'));
registrationForm.add(new Button('Register'));const mainForm = new Form('Main Form');
mainForm.add(loginForm);
mainForm.add(registrationForm);// 渲染整个 UI 树
mainForm.render();
console.log(`Total components: ${mainForm.getComponentSize()}`);

4. 行为型设计模式

行为型设计模式关注对象之间的通信和职责分配。

4.1 观察者模式

观察者模式定义对象间的一对多依赖关系,使一个对象改变时,所有依赖它的对象都得到通知。

// 主题
class Subject {constructor() {this.observers = [];}subscribe(observer) {this.observers.push(observer);}unsubscribe(observer) {this.observers = this.observers.filter(obs => obs !== observer);}notify(data) {this.observers.forEach(observer => observer.update(data));}
}// 观察者
class Observer {constructor(name) {this.name = name;}update(data) {console.log(`${this.name} received: ${data}`);}
}// 使用
const subject = new Subject();const observer1 = new Observer('Observer 1');
const observer2 = new Observer('Observer 2');subject.subscribe(observer1);
subject.subscribe(observer2);subject.notify('Hello World!');
// "Observer 1 received: Hello World!"
// "Observer 2 received: Hello World!"subject.unsubscribe(observer1);
subject.notify('Hello Again!');
// "Observer 2 received: Hello Again!"

4.2 策略模式

策略模式定义了一系列算法,将每个算法封装起来,使它们可以互换使用。

// 策略接口
class PaymentStrategy {pay(amount) {throw new Error('pay method must be implemented');}
}// 具体策略
class CreditCardStrategy extends PaymentStrategy {constructor(cardNumber, name, cvv, expiryDate) {super();this.cardNumber = cardNumber;this.name = name;this.cvv = cvv;this.expiryDate = expiryDate;}pay(amount) {console.log(`Paying ${amount} using Credit Card`);// 处理信用卡支付逻辑}
}class PayPalStrategy extends PaymentStrategy {constructor(email, password) {super();this.email = email;this.password = password;}pay(amount) {console.log(`Paying ${amount} using PayPal`);// 处理 PayPal 支付逻辑}
}// 上下文
class ShoppingCart {constructor() {this.items = [];}addItem(item) {this.items.push(item);}calculateTotal() {return this.items.reduce((total, item) => total + item.price, 0);}checkout(paymentStrategy) {const amount = this.calculateTotal();paymentStrategy.pay(amount);}
}// 客户端代码
const cart = new ShoppingCart();
cart.addItem({ name: 'Item 1', price: 100 });
cart.addItem({ name: 'Item 2', price: 50 });// 使用信用卡支付
cart.checkout(new CreditCardStrategy('1234-5678-9012-3456', 'John Doe', '123', '12/25'));// 使用 PayPal 支付
cart.checkout(new PayPalStrategy('john@example.com', 'password'));// 使用 JavaScript 函数作为策略
const paymentStrategies = {creditCard: function(amount) {console.log(`Paying ${amount} using Credit Card`);},paypal: function(amount) {console.log(`Paying ${amount} using PayPal`);},bitcoin: function(amount) {console.log(`Paying ${amount} using Bitcoin`);}
};function processPayment(amount, strategy) {return paymentStrategies[strategy](amount);
}processPayment(150, 'creditCard'); // "Paying 150 using Credit Card"
processPayment(150, 'paypal'); // "Paying 150 using PayPal"

4.3 命令模式

命令模式将请求封装为对象,使用者和发送者解耦。

// 命令接口
class Command {execute() {throw new Error('execute method must be implemented');}undo() {throw new Error('undo method must be implemented');}
}// 接收者
class Light {constructor() {this.isOn = false;}turnOn() {this.isOn = true;console.log('Light is now ON');}turnOff() {this.isOn = false;console.log('Light is now OFF');}
}// 具体命令
class TurnOnCommand extends Command {constructor(light) {super();this.light = light;}execute() {this.light.turnOn();}undo() {this.light.turnOff();}
}class TurnOffCommand extends Command {constructor(light) {super();this.light = light;}execute() {this.light.turnOff();}undo() {this.light.turnOn();}
}// 调用者
class RemoteControl {constructor() {this.commands = [];this.history = [];}setCommand(slot, command) {this.commands[slot] = command;}pressButton(slot) {const command = this.commands[slot];if (command) {command.execute();this.history.push(command);}}pressUndoButton() {const command = this.history.pop();if (command) {command.undo();}}
}// 客户端代码
const light = new Light();
const turnOn = new TurnOnCommand(light);
const turnOff = new TurnOffCommand(light);const remote = new RemoteControl();
remote.setCommand(0, turnOn);
remote.setCommand(1, turnOff);remote.pressButton(0); // "Light is now ON"
remote.pressButton(1); // "Light is now OFF"
remote.pressUndoButton(); // "Light is now ON"

4.4 迭代器模式

迭代器模式提供一种顺序访问集合元素的方法,而不暴露内部表示。

// 自定义迭代器
class ArrayIterator {constructor(array) {this.array = array;this.index = 0;}hasNext() {return this.index < this.array.length;}next() {return this.hasNext() ? this.array[this.index++] : null;}
}// 可迭代集合
class Collection {constructor() {this.items = [];}addItem(item) {this.items.push(item);}getIterator() {return new ArrayIterator(this.items);}
}// 使用迭代器
const collection = new Collection();
collection.addItem('Item 1');
collection.addItem('Item 2');
collection.addItem('Item 3');const iterator = collection.getIterator();
while (iterator.hasNext()) {console.log(iterator.next());
}// ES6 实现迭代器协议和可迭代协议
class NumberRange {constructor(start, end) {this.start = start;this.end = end;}// 使对象可迭代[Symbol.iterator]() {let current = this.start;const end = this.end;// 迭代器对象return {next() {if (current <= end) {return { value: current++, done: false };} else {return { done: true };}}};}
}// 使用 for...of 遍历
for (const num of new NumberRange(1, 5)) {console.log(num); // 1, 2, 3, 4, 5
}

4.5 中介者模式

中介者模式通过引入中介对象来减少对象之间的直接通信,降低耦合度。

// 中介者
class ChatRoom {constructor() {this.users = {};}register(user) {this.users[user.name] = user;user.chatRoom = this;}send(message, from, to) {if (to) {// 私聊消息this.users[to].receive(message, from);} else {// 广播消息for (const key in this.users) {if (this.users[key] !== from) {this.users[key].receive(message, from);}}}}
}// 同事类
class User {constructor(name) {this.name = name;this.chatRoom = null;}send(message, to) {this.chatRoom.send(message, this, to);}receive(message, from) {console.log(`${from.name} to ${this.name}: ${message}`);}
}// 使用
const chatRoom = new ChatRoom();const john = new User('John');
const jane = new User('Jane');
const bob = new User('Bob');chatRoom.register(john);
chatRoom.register(jane);
chatRoom.register(bob);john.send('Hi everyone!');
jane.send('Hey John!', 'John');
bob.send('Hello!');

5. 实际应用案例

5.1 表单验证系统

结合了策略模式和装饰器模式。

// 验证策略
const validators = {required: (value) => value.trim() !== '' ? null : 'This field is required',minLength: (value, min) => value.length >= min ? null : `Must be at least ${min} characters`,maxLength: (value, max) => value.length <= max ? null : `Cannot exceed ${max} characters`,email: (value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value) ? null : 'Invalid email format',pattern: (value, regex) => regex.test(value) ? null : 'Invalid format'
};// 表单验证器类
class FormValidator {constructor() {this.validations = {};}// 添加验证规则addValidation(field, validations) {this.validations[field] = validations;}

结语
感谢您的阅读!期待您的一键三连!欢迎指正!

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/76235.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

网络安全防护技术

边界安全防护——防火墙 控制&#xff1a;在网络连接点上建立一个安全控制点&#xff0c;对进出数据进行限制隔离&#xff1a;将需要保护的网络与不可信任网络进行隔离&#xff0c;隐藏信息并进行安全防护记录&#xff1a;对进出数据进行检查&#xff0c;记录相关信息 防火墙…

Spring MVC 视图解析器(JSP、Thymeleaf、Freemarker、 JSON/HTML、Bean)详解

Spring MVC 视图解析器详解 1. 视图解析器概述 视图解析器&#xff08;ViewResolver&#xff09;是 Spring MVC 的核心组件&#xff0c;负责将控制器返回的视图名称&#xff08;如 success&#xff09;转换为具体的 View 对象&#xff08;如 Thymeleaf 模板或 JSP 文件&#x…

# 爬虫技术的实现

手把手教你网络爬虫&#xff1a;从入门到实践 一、网络爬虫简介 网络爬虫&#xff08;Web Crawler&#xff09;是一种自动化获取互联网数据的程序&#xff0c;广泛应用于搜索引擎、数据分析、市场调研等领域。通过模拟浏览器行为&#xff0c;爬虫可以高效地从网页中提取结构化…

【HarmonyOS 5】鸿蒙中@State的原理详解

一、State在鸿蒙中是做什么的&#xff1f; State 是 HarmonyOS ArkTS 框架中用于管理组件状态的核心装饰器&#xff0c;其核心作用是实现数据驱动 UI 的响应式编程模式。通过将变量标记为 State&#xff0c;开发者可以确保当状态值发生变化时&#xff0c;依赖该状态的 UI 组件…

influxdb数据导出笔记

influx query ‘from(bucket: “byt-grid-data”) |> range(start: 2025-04-01T00:00:00Z, stop: 2025-04-02T23:59:59Z) |> filter(fn: > r[“_measurement”] “byt-gzsn-hsxn-sc-dcs”) |> filter(fn: > r[“_field”] “F_ACT_FZZ02_FB_O”) |> filt…

HTTP Content-Type:深入解析与应用

HTTP Content-Type:深入解析与应用 引言 在互联网世界中,数据传输是至关重要的。而HTTP协议作为最常用的网络协议之一,其在数据传输过程中扮演着关键角色。其中,HTTP Content-Type头字段在数据传输中发挥着至关重要的作用。本文将深入解析HTTP Content-Type,并探讨其在实…

使用SQL查询ES数据

使用SQL查询ES数据 32 进阶&#xff1a;使用SQL查询ES数据环境准备利用脚本导入测试数据 SQL学习基本查询排序查询过滤查询范围查询分组查询(group)分组过滤查询(grouphaving)聚合函数统计limit查询分页查询 32 进阶&#xff1a;使用SQL查询ES数据 环境准备 需要首先安装ES8.…

禁止页面滚动的方法-微信小程序

在微信小程序中&#xff0c;有几种方法可以禁止页面滚动&#xff1a; 一、通过页面配置禁止滚动 在页面的JSON配置文件中设置&#xff0c;此方法完全禁止页面的滚动行为&#xff1a; {"disableScroll": true }二、通过 CSS 样式禁止滚动 在页面的WXSS文件中添加&…

用户画像(https://github.com/memodb-io/memobase)应用

1.下载项目的源代码,我们要先启动后端,用docker启动 cd src/server cp .env.example .env cp ./api/config.yaml.example ./api/config.yaml 这里我的配置内容如下config.yaml(因为我是调用的符合openai格式的大模型,所以我没改,如果要是别的大模型的话,需要自己再做兼容…

微信小程序生成某个具体页面的二维码

微信小程序&#xff0c;如果要生成某个具体页面&#xff0c;而非首页的二维码&#xff0c;体验和正式的生成方法如下&#xff1a; 1、体验版二维码&#xff1a; 管理---版本管理---修改页面路径&#xff0c;输入具体页面的路径以及参数&#xff0c;生成的是二维码 2、正式小程…

【今日三题】小乐乐改数字 (模拟) / 十字爆破 (预处理+模拟) / 比那名居的桃子 (滑窗 / 前缀和)

⭐️个人主页&#xff1a;小羊 ⭐️所属专栏&#xff1a;每日两三题 很荣幸您能阅读我的文章&#xff0c;诚请评论指点&#xff0c;欢迎欢迎 ~ 目录 小乐乐改数字 (模拟)十字爆破 (预处理模拟&#xff09;比那名居的桃子 (滑窗 / 前缀和) 小乐乐改数字 (模拟) 小乐乐改数字…

四旋翼无人机手动模式

无人机的手动模式&#xff08;Manual Mode&#xff09;是指飞手完全通过遥控器手动控制无人机的飞行姿态、高度、方向和速度&#xff0c;‌无需依赖自动稳定系统或辅助功能‌&#xff08;如GPS定位、气压计定高、视觉避障等&#xff09;。这种模式赋予操作者最大的操控自由度&a…

C++高精度算法(加、减、乘)

首先声明&#xff0c;没有除法是因为我不会&#xff08;手动狗头_doge&#xff09; 简介 顾名思义&#xff0c;高精度算法是用来算一些超级大的数&#xff0c;比如长到 longlong 都存不下的那种&#xff0c;还有就是小数点后好多位&#xff0c;double都存不下的那种&#xff…

思科交换机配置

以下是交换机配置的详细步骤指南&#xff0c;适用于Cisco交换机&#xff0c;其他品牌需调整命令&#xff1a; 1. 初始连接与基本配置 连接方式&#xff1a;使用Console线连接交换机&#xff0c;通过终端软件&#xff08;如PuTTY&#xff09;登录。波特率&#xff1a;9600&…

数据质量问题中,数据及时性怎么保证?如何有深度体系化回答!

数据治理&#xff0c;数据质量这快是中大厂&#xff0c;高阶大数据开发面试必备技能&#xff0c;企业基于大数据底座去做数仓&#xff0c;那么首先需要保障的就是数据质量。 数据质量的重要性在现代企业中变得越发突出。以下是数据质量的几个关键方面&#xff0c;说明其对企业…

【学习笔记】CPU 的“超线程”是什么?

1. 什么是超线程&#xff1f; 超线程&#xff08;Hyper-Threading&#xff09;是Intel的技术&#xff0c;让一个物理CPU核心模拟出两个逻辑核心。 效果&#xff1a;4核CPU在系统中显示为8线程。 本质&#xff1a;通过复用空闲的硬件单元&#xff08;如ALU、FPU&#xff09;&a…

闭包的理解

一、闭包的概念 当通过调用外部函数返回的内部函数后&#xff0c;即使外部函数已经执行结束了&#xff0c;但是被内部函数引用的外部函数的变量依然会保存在内存中&#xff0c;我们把引用了其他函数作用域变量的函数和这些被引用变量的集合&#xff0c;称为闭包&#xff08;Clo…

从小米汽车事故反思 LabVIEW 开发

近期&#xff0c;小米汽车的一起严重事故引发了社会各界的广泛关注。这起事故不仅让我们对智能汽车的安全性产生了深深的思考&#xff0c;也为 LabVIEW 开发领域带来了诸多值得汲取的知识与领悟。 在智能汽车领域&#xff0c;尤其是涉及到智能驾驶辅助系统时&#xff0c;安全是…

项目进度延误的十大原因及应对方案

项目进度延误主要源于以下十大原因&#xff1a;目标不明确、需求频繁变更、资源配置不足或不合理、沟通不畅、风险管理不足、缺乏有效的项目监控、技术难题未及时解决、团队协作效率低下、决策链过长、外部因素影响。其中&#xff0c;需求频繁变更是导致延误的关键因素之一&…

AI 赋能 DBA:如何用 DeepSeek 等大模型简化数据库管理工作

AI 赋能 DBA:如何用 DeepSeek 等大模型简化数据库管理工作 摘要: 数据库管理员(DBA)的工作涉及 SQL 优化、故障排查、性能监控等复杂任务。而 DeepSeek、ChatGPT 等大模型可以大幅减少重复劳动,提高 DBA 的工作效率。本文将结合真实案例,介绍如何利用 AI 优化 DBA 工作流…