【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.pswp.cn/pingmian/76235.shtml
繁體地址,請注明出處:http://hk.pswp.cn/pingmian/76235.shtml
英文地址,請注明出處:http://en.pswp.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 工作流…