Android開發中的11種行為型設計模式深度解析

在Android應用開發中,設計模式是解決特定問題的可重用方案,其中行為型設計模式尤其重要,它們專注于對象之間的通信和職責分配。本文將深入解析Android開發中最常用的11種行為型設計模式,每個模式都配有詳細的介紹和實際應用示例,幫助開發者構建更靈活、可維護的應用架構。

1. 觀察者模式(Observer Pattern)

模式定義:定義對象間一對多的依賴關系,當一個對象狀態改變時,所有依賴它的對象都會自動收到通知并更新9。

Android典型應用

  • LiveData的生命周期感知數據觀察

  • RxJava的響應式編程模型

  • 視圖控件的點擊事件監聽(View.setOnClickListener())

  • RecyclerView.Adapter的數據更新機制

實現示例

// 被觀察者
public class NewsPublisher {private List<Subscriber> subscribers = new ArrayList<>();public void addSubscriber(Subscriber s) {subscribers.add(s);}public void notifySubscribers(String news) {for (Subscriber s : subscribers) {s.update(news);}}
}// 觀察者接口
public interface Subscriber {void update(String news);
}// 具體觀察者
public class NewsReader implements Subscriber {@Overridepublic void update(String news) {System.out.println("收到新聞更新: " + news);}
}// 使用
NewsPublisher publisher = new NewsPublisher();
publisher.addSubscriber(new NewsReader());
publisher.notifySubscribers("Android 14新特性發布");

優點:解耦觀察者和被觀察者,支持動態添加和移除觀察者,實現廣播通信機制9。

注意事項:在Activity/Fragment中使用時需注意內存泄漏問題,避免持有已銷毀的UI引用。

2. 策略模式(Strategy Pattern)

模式定義:定義一系列算法,封裝每個算法,并使它們可以互相替換15。

Android典型應用

  • RecyclerView的不同布局管理器(LinearLayoutManager/GridLayoutManager)

  • 動畫插值器(Interpolator)的各種實現

  • 圖片加載庫的不同緩存策略

  • 支付模塊的不同支付方式實現

實現示例

// 策略接口
public interface ImageCacheStrategy {void loadImage(Context context, String url, ImageView imageView);
}// 具體策略:內存緩存
public class MemoryCacheStrategy implements ImageCacheStrategy {@Overridepublic void loadImage(Context context, String url, ImageView imageView) {// 內存緩存實現Log.d("Cache", "Loading from memory cache");}
}// 具體策略:磁盤緩存
public class DiskCacheStrategy implements ImageCacheStrategy {@Overridepublic void loadImage(Context context, String url, ImageView imageView) {// 磁盤緩存實現Log.d("Cache", "Loading from disk cache");}
}// 上下文
public class ImageLoader {private ImageCacheStrategy strategy;public void setStrategy(ImageCacheStrategy strategy) {this.strategy = strategy;}public void displayImage(Context context, String url, ImageView imageView) {strategy.loadImage(context, url, imageView);}
}// 使用
ImageLoader loader = new ImageLoader();
loader.setStrategy(new MemoryCacheStrategy());
loader.displayImage(context, "http://example.com/image.jpg", imageView);

最佳實踐:結合依賴注入(如Dagger)來管理策略對象,使代碼更清晰5。

3. 模板方法模式(Template Method Pattern)

模式定義:定義一個操作中的算法骨架,將某些步驟延遲到子類中實現247。

Android典型應用

  • ActivityFragment的生命周期方法

  • AsyncTask的任務執行流程

  • 自定義View的繪制流程

  • 基類Activity/Fragment的通用邏輯封裝

實現示例

public abstract class BaseActivity extends AppCompatActivity {@Overrideprotected final void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(getLayoutId());initViews();initData();setupListeners();}protected abstract int getLayoutId();protected abstract void initViews();protected abstract void initData();protected abstract void setupListeners();// 鉤子方法,可選實現protected void onCustomEvent() {// 默認空實現}
}// 具體實現
public class MainActivity extends BaseActivity {@Overrideprotected int getLayoutId() {return R.layout.activity_main;}@Overrideprotected void initViews() {// 初始化視圖}@Overrideprotected void initData() {// 初始化數據}@Overrideprotected void setupListeners() {// 設置監聽器}@Overrideprotected void onCustomEvent() {// 自定義實現}
}

核心思想:將不變的部分(算法骨架)放在父類,可變部分(具體實現)放在子類7。

4. 命令模式(Command Pattern)

模式定義:將一個請求封裝為對象,從而允許用戶使用不同的請求參數化其他對象6。

Android典型應用

  • 事件處理系統

  • 撤銷/重做功能實現

  • 異步任務調度

  • 廣播接收器

實現示例

// 命令接口
public interface Command {void execute();
}// 具體命令
public class LightOnCommand implements Command {private Light light;public LightOnCommand(Light light) {this.light = light;}@Overridepublic void execute() {light.turnOn();}
}// 接收者
public class Light {public void turnOn() {Log.d("Command", "Light is on");}
}// 調用者
public class RemoteControl {private Command command;public void setCommand(Command command) {this.command = command;}public void pressButton() {command.execute();}
}// 使用
Light light = new Light();
Command lightOn = new LightOnCommand(light);
RemoteControl remote = new RemoteControl();
remote.setCommand(lightOn);
remote.pressButton();

優勢:將請求發送者與接收者解耦,支持命令隊列和日志記錄6。

5. 狀態模式(State Pattern)

模式定義:允許對象在內部狀態改變時改變其行為,看起來像是改變了其類8。

Android典型應用

  • 播放器狀態管理(播放/暫停/停止)

  • 用戶登錄狀態管理

  • 訂單狀態流轉

  • 網絡連接狀態處理

實現示例

// 狀態接口
public interface PlayerState {void play(MediaPlayer player);void pause(MediaPlayer player);
}// 具體狀態:播放狀態
public class PlayingState implements PlayerState {@Overridepublic void play(MediaPlayer player) {// 已經是播放狀態,不做操作}@Overridepublic void pause(MediaPlayer player) {player.pause();player.setState(new PausedState());}
}// 具體狀態:暫停狀態
public class PausedState implements PlayerState {@Overridepublic void play(MediaPlayer player) {player.start();player.setState(new PlayingState());}@Overridepublic void pause(MediaPlayer player) {// 已經是暫停狀態,不做操作}
}// 上下文
public class MediaPlayer {private PlayerState state;public MediaPlayer() {this.state = new PausedState();}public void setState(PlayerState state) {this.state = state;}public void play() {state.play(this);}public void pause() {state.pause(this);}// 其他方法...
}// 使用
MediaPlayer player = new MediaPlayer();
player.play();  // 從暫停切換到播放
player.pause(); // 從播放切換到暫停

優點:消除大量條件語句,使狀態轉換顯式化8。

6. 責任鏈模式(Chain of Responsibility Pattern)

模式定義:將請求的發送者和接收者解耦,使多個對象都有機會處理請求10。

Android典型應用

  • Android事件分發機制

  • 網絡請求攔截器鏈(如OkHttp)

  • 權限檢查流程

  • 異常處理鏈

實現示例

// 處理器接口
public interface Handler {void setNext(Handler handler);void handle(Request request);
}// 抽象處理器
public abstract class AbstractHandler implements Handler {private Handler next;@Overridepublic void setNext(Handler handler) {this.next = handler;}@Overridepublic void handle(Request request) {if (canHandle(request)) {process(request);} else if (next != null) {next.handle(request);} else {Log.d("Chain", "No handler found for request");}}protected abstract boolean canHandle(Request request);protected abstract void process(Request request);
}// 具體處理器:登錄檢查
public class AuthHandler extends AbstractHandler {@Overrideprotected boolean canHandle(Request request) {return request.needsAuth();}@Overrideprotected void process(Request request) {Log.d("Chain", "Handling authentication");// 實際認證邏輯}
}// 具體處理器:緩存檢查
public class CacheHandler extends AbstractHandler {@Overrideprotected boolean canHandle(Request request) {return request.isCacheable();}@Overrideprotected void process(Request request) {Log.d("Chain", "Checking cache");// 實際緩存邏輯}
}// 使用
Handler chain = new AuthHandler();
chain.setNext(new CacheHandler());Request request = new Request(true, false); // 需要認證,不可緩存
chain.handle(request);

特點:動態構建處理鏈,靈活添加或修改處理邏輯10。

7. 迭代器模式(Iterator Pattern)

模式定義:提供一種方法順序訪問聚合對象中的各個元素,而又不暴露其內部表示4。

Android典型應用

  • 數據庫查詢結果遍歷(Cursor)

  • 集合類遍歷

  • 自定義數據結構遍歷

  • RecyclerView數據訪問

實現示例

// 迭代器接口
public interface Iterator<T> {boolean hasNext();T next();
}// 聚合接口
public interface Aggregate<T> {Iterator<T> createIterator();
}// 具體聚合:用戶集合
public class UserCollection implements Aggregate<User> {private List<User> users = new ArrayList<>();public void addUser(User user) {users.add(user);}@Overridepublic Iterator<User> createIterator() {return new UserIterator(users);}
}// 具體迭代器
public class UserIterator implements Iterator<User> {private List<User> users;private int position = 0;public UserIterator(List<User> users) {this.users = users;}@Overridepublic boolean hasNext() {return position < users.size();}@Overridepublic User next() {User user = users.get(position);position++;return user;}
}// 使用
UserCollection collection = new UserCollection();
collection.addUser(new User("Alice"));
collection.addUser(new User("Bob"));Iterator<User> iterator = collection.createIterator();
while (iterator.hasNext()) {User user = iterator.next();Log.d("Iterator", "User: " + user.getName());
}

優勢:統一遍歷接口,支持多種遍歷方式而不暴露集合內部結構。

8. 中介者模式(Mediator Pattern)

模式定義:定義一個中介對象來封裝一系列對象之間的交互9。

Android典型應用

  • MVP架構中的Presenter

  • 聊天室實現

  • 組件間通信

  • 事件總線(EventBus)

實現示例

// 中介者接口
public interface ChatMediator {void sendMessage(String msg, User user);void addUser(User user);
}// 具體中介者:聊天室
public class ChatRoom implements ChatMediator {private List<User> users = new ArrayList<>();@Overridepublic void sendMessage(String msg, User user) {for (User u : users) {if (u != user) {u.receive(msg);}}}@Overridepublic void addUser(User user) {users.add(user);}
}// 同事類
public abstract class User {protected ChatMediator mediator;protected String name;public User(ChatMediator mediator, String name) {this.mediator = mediator;this.name = name;}public abstract void send(String msg);public abstract void receive(String msg);
}// 具體同事類
public class ChatUser extends User {public ChatUser(ChatMediator mediator, String name) {super(mediator, name);}@Overridepublic void send(String msg) {Log.d("Mediator", name + " sends: " + msg);mediator.sendMessage(msg, this);}@Overridepublic void receive(String msg) {Log.d("Mediator", name + " receives: " + msg);}
}// 使用
ChatMediator mediator = new ChatRoom();
User alice = new ChatUser(mediator, "Alice");
User bob = new ChatUser(mediator, "Bob");mediator.addUser(alice);
mediator.addUser(bob);alice.send("Hi there!");
bob.send("Hello Alice!");

優點:減少對象間直接依賴,集中控制交互邏輯。

9. 備忘錄模式(Memento Pattern)

模式定義:在不破壞封裝性的前提下,捕獲并外部化對象的內部狀態,以便以后可以恢復4。

Android典型應用

  • Activity狀態保存(onSaveInstanceState)

  • 游戲存檔/讀檔

  • 撤銷操作實現

  • 表單數據臨時保存

實現示例

// 備忘錄:保存編輯器狀態
public class EditorMemento {private final String content;public EditorMemento(String content) {this.content = content;}public String getContent() {return content;}
}// 原發器:文本編輯器
public class TextEditor {private String content;public void type(String words) {content = words;}public String getContent() {return content;}public EditorMemento save() {return new EditorMemento(content);}public void restore(EditorMemento memento) {content = memento.getContent();}
}// 管理者:負責保存備忘錄
public class History {private Stack<EditorMemento> states = new Stack<>();public void push(EditorMemento memento) {states.push(memento);}public EditorMemento pop() {return states.pop();}
}// 使用
TextEditor editor = new TextEditor();
History history = new History();editor.type("First version");
history.push(editor.save());editor.type("Second version");
history.push(editor.save());editor.type("Third version");
System.out.println("Current content: " + editor.getContent());// 撤銷到上一個版本
editor.restore(history.pop());
System.out.println("After undo: " + editor.getContent());

特點:實現狀態保存與恢復,不暴露對象內部細節。

10. 訪問者模式(Visitor Pattern)

模式定義:表示一個作用于某對象結構中的各元素的操作,可以在不改變各元素類的前提下定義作用于這些元素的新操作4。

Android典型應用

  • 編譯器語法樹分析

  • 復雜對象結構操作

  • APT(Annotation Processing Tool)

  • 報表生成

實現示例

// 元素接口
public interface ReportElement {void accept(ReportVisitor visitor);
}// 具體元素:固定支出
public class FixedCost implements ReportElement {private double amount;public FixedCost(double amount) {this.amount = amount;}public double getAmount() {return amount;}@Overridepublic void accept(ReportVisitor visitor) {visitor.visit(this);}
}// 具體元素:可變支出
public class VariableCost implements ReportElement {private double[] amounts;public VariableCost(double[] amounts) {this.amounts = amounts;}public double[] getAmounts() {return amounts;}@Overridepublic void accept(ReportVisitor visitor) {visitor.visit(this);}
}// 訪問者接口
public interface ReportVisitor {void visit(FixedCost fixedCost);void visit(VariableCost variableCost);
}// 具體訪問者:成本計算
public class CostCalculator implements ReportVisitor {private double total;@Overridepublic void visit(FixedCost fixedCost) {total += fixedCost.getAmount();}@Overridepublic void visit(VariableCost variableCost) {for (double amount : variableCost.getAmounts()) {total += amount;}}public double getTotal() {return total;}
}// 使用
List<ReportElement> elements = new ArrayList<>();
elements.add(new FixedCost(1000));
elements.add(new VariableCost(new double[]{200, 300, 400}));CostCalculator calculator = new CostCalculator();
for (ReportElement element : elements) {element.accept(calculator);
}System.out.println("Total cost: " + calculator.getTotal());

優勢:將算法與對象結構分離,便于添加新操作而不修改元素類。

11. 解釋器模式(Interpreter Pattern)

模式定義:給定一個語言,定義它的文法的一種表示,并定義一個解釋器,這個解釋器使用該表示來解釋語言中的句子4。

Android典型應用

  • 正則表達式處理

  • SQL解析

  • 數學公式計算

  • 領域特定語言(DSL)

實現示例

// 抽象表達式
public interface Expression {boolean interpret(String context);
}// 終結符表達式
public class TerminalExpression implements Expression {private String data;public TerminalExpression(String data) {this.data = data;}@Overridepublic boolean interpret(String context) {return context.contains(data);}
}// 或表達式
public class OrExpression implements Expression {private Expression expr1;private Expression expr2;public OrExpression(Expression expr1, Expression expr2) {this.expr1 = expr1;this.expr2 = expr2;}@Overridepublic boolean interpret(String context) {return expr1.interpret(context) || expr2.interpret(context);}
}// 與表達式
public class AndExpression implements Expression {private Expression expr1;private Expression expr2;public AndExpression(Expression expr1, Expression expr2) {this.expr1 = expr1;this.expr2 = expr2;}@Overridepublic boolean interpret(String context) {return expr1.interpret(context) && expr2.interpret(context);}
}// 使用
Expression robert = new TerminalExpression("Robert");
Expression john = new TerminalExpression("John");
Expression or = new OrExpression(robert, john);Expression married = new TerminalExpression("Married");
Expression julie = new TerminalExpression("Julie");
Expression and = new AndExpression(julie, married);System.out.println("John is male? " + or.interpret("John"));
System.out.println("Julie is a married woman? " + and.interpret("Married Julie"));

適用場景:需要解釋執行特定語言的場合,特別是簡單語法的情況。

總結

行為型設計模式在Android開發中扮演著重要角色,它們幫助我們:

  1. 解耦對象間的依賴:如觀察者模式、中介者模式

  2. 封裝算法和操作:如策略模式、模板方法模式

  3. 管理狀態和流程:如狀態模式、責任鏈模式

  4. 支持擴展和變化:如訪問者模式、命令模式

在實際開發中,應根據具體需求選擇合適的模式,避免過度設計。同時,結合Kotlin語言特性(如高階函數、擴展函數)可以簡化部分模式的實現。

最佳實踐建議

  • 理解模式解決的問題,而非機械套用

  • 優先考慮代碼可讀性和可維護性

  • 結合Android組件生命周期設計

  • 編寫單元測試驗證模式實現

設計模式是工具而非目標,合理運用才能構建出高質量、易維護的Android應用。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/89882.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/89882.shtml
英文地址,請注明出處:http://en.pswp.cn/web/89882.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Python 模塊未找到?這樣解決“ModuleNotFoundError”

在 Python 開發中&#xff0c;遇到“ModuleNotFoundError”時&#xff0c;通常是因為 Python 解釋器無法找到你嘗試導入的模塊。這可能是由于多種原因導致的&#xff0c;比如模塊未安裝、路徑不正確、虛擬環境未激活等。今天&#xff0c;就讓我們一起探討如何解決“ModuleNotFo…

Numpy庫,矩陣形狀與維度操作

目錄 一.numpy庫簡介與安裝 numpy庫的安裝 二.numpy核心功能 1.矩陣處理 2.數學運算 三.數據的維度與屬性 1.維度管理 2.屬性方法 四.數據類型與存儲范圍 五.矩陣形狀與維度操作 六.數據升維與reshape()方法 一.numpy庫簡介與安裝 NumPy是Python中用于科學計算的核心…

圖論(2):最短路

最短路一、模板1. Floyd2. 01BFS3. SPFA4. Dijkstra&#xff08;弱化版&#xff09;5. Dijkstra&#xff08;優化版&#xff09;二、例題1. Floyd1.1 傳送門1.2 無向圖最小環1.3 災后重建1.4 飛豬2. 01BFS2.1 Kathiresan2.2 障礙路線2.3 奇妙的棋盤3. SPFA3.1 奶牛派對3.2 營救…

“融合進化,智領未來”電科金倉引領數字化轉型新紀元

一、融合進化 智領未來電科金倉2025產品發布會重磅開啟&#xff01; 7月15日&#xff0c;以“融合進化 智領未來”為主題的電科金倉2025產品發布會在北京舉辦。產品發布會上展示了四款代表未來數字化趨勢的創新性產品。這些產品不僅涵蓋了數據庫技術&#xff0c;還涉及到數據集…

常規筆記本和加固筆記本的區別

在現代科技產品中&#xff0c;筆記本電腦因其便攜性和功能性被廣泛應用。根據使用場景和需求的不同&#xff0c;筆記本可分為常規筆記本和加固筆記本&#xff0c;二者在多個方面存在顯著區別。適用場景是區分二者的重要標志。常規筆記本主要面向普通消費者和辦公人群&#xff0…

Shell 腳本編程全面學習指南

前言Shell 腳本編程是 Linux 和 Unix 系統管理、自動化任務的核心工具之一。通過 Shell 腳本&#xff0c;你可以自動化重復性操作、簡化復雜流程、提高系統管理效率&#xff0c;甚至構建完整的自動化運維工具。本文將帶你從基礎到進階&#xff0c;全面學習 Shell 腳本編程&…

DelayQueue延遲隊列的使用

1、DelayQueue簡介 DelayQueue 也是 Java 并發包&#xff08;java.util.concurrent&#xff09;中的一個特殊隊列,用于在指定的延遲時間之后處理元素。 DelayQueue的一些關鍵特性&#xff1a; 延遲元素處理&#xff1a;只有當元素的延遲時間到期時&#xff0c;元素才能被取出…

QT6 源,七章對話框與多窗體(6) 顏色對話框 QColorDialog :本類的屬性,信號函數,靜態成員函數,以及源代碼

&#xff08;1&#xff09;本類的繼承關系如下 &#xff1a;&#xff08;2&#xff09; 對于本標準顏色對話框來講&#xff0c;學會使用其靜態函數以獲取到顏色就足夠了。&#xff08;3&#xff09; 開始學習本類的靜態成員函數 &#xff1a;&#xff08;4&#xff09;測試一下…

金倉數據庫:融合進化,智領未來——2025年數據庫技術革命的深度解析

引言 在數字中國戰略的推動下&#xff0c;數據庫作為數字經濟的基礎設施&#xff0c;正經歷著前所未有的技術重構。2025年7月15日&#xff0c;電科金倉以"融合進化&#xff0c;智領未來"為主題&#xff0c;發布了新一代數據庫產品矩陣&#xff0c;標志著國產數據庫在…

【人工智能99問】卷積神經網絡(CNN)的結構和原理是什么?(10/99)

文章目錄卷積神經網絡&#xff08;CNN&#xff09;的結構及原理一、CNN的核心結構1. 輸入層&#xff08;Input Layer&#xff09;2. 卷積層&#xff08;Convolutional Layer&#xff09;2. 卷積層的核心機制&#xff1a;局部感受野與權值共享3. 池化層&#xff08;Pooling Laye…

CCF編程能力等級認證GESP—C++7級—20250628

CCF編程能力等級認證GESP—C7級—20250628單選題&#xff08;每題 2 分&#xff0c;共 30 分&#xff09;判斷題&#xff08;每題 2 分&#xff0c;共 20 分&#xff09;編程題 (每題 25 分&#xff0c;共 50 分)線圖調味平衡單選題&#xff08;每題 2 分&#xff0c;共 30 分&…

《Python 類設計模式:屬性分類(類屬性 VS 實例屬性)與方法類型(實例 / 類 / 靜態)詳解》

Python 類和對象&#xff1a;從 "圖紙" 到 "實物" 的編程思維面向對象編程&#xff08;Object-Oriented Programming&#xff0c;簡稱OOP &#xff09;是一種通過組織對象來編程的方法。1.初識類和對象&#xff1a;用生活例子看透核心概念1.1類-class物與類…

Eureka服務端啟動

目錄 1、相關文章 2、創建eureka-server子工程 3、父工程build.gradle引入版本依賴管理 4、子工程build.gradle引入依賴 5、將main重命名為EurekaApplication并修改代碼 6、添加application.yml文件 7、啟動工程并訪問 8、訪問界面如下 9、 完整目錄結構 1、相關文章 …

AWS Partner: Sales Accreditation (Business)

AWS Partner: Sales Accreditation &#xff08;Business&#xff09;云概念和AWS云計算什么是云計算&#xff1f;計算的演變趨勢云計算部署模型AWS 客戶采用的模式為什么客戶選擇AWSAWS競爭優勢高可用的全球基礎設施AWS服務服務廣度和深度AWS產品和服務服務類別AWS解決方案庫A…

深入理解設計模式之中介者模式:解耦對象交互的利器

為什么需要中介者&#xff1f;在軟件開發中&#xff0c;我們經常會遇到對象之間需要相互通信的場景。當系統規模較小時&#xff0c;對象直接相互引用并通信可能不會帶來太大問題。但隨著系統復雜度增加&#xff0c;對象間的交互關系會變得錯綜復雜&#xff0c;形成一個復雜的網…

從 0 安裝 Label Studio:搭建可后臺運行的數據標注平臺(systemd 實踐

本文將介紹如何使用 pip 安裝 Label Studio&#xff0c;并通過 systemd 實現開機自啟與后臺運行&#xff0c;適用搭建個人項目的數據標注平臺。 一、Label Studio 簡介 Label Studio 是一個開源、跨模態的數據標注工具&#xff0c;支持文本、圖像、音頻、視頻、HTML等多種類型…

【數據結構】鏈表(linked list)

目錄 一、鏈表的介紹 二、單鏈表 1. 單鏈表的初始化 2. 單鏈表的插入 &#xff08;1&#xff09;動態申請一個節點 &#xff08;2&#xff09;頭插法 &#xff08;3&#xff09;尾插法 &#xff08;4&#xff09;按照位置來插入 &#xff08;5&#xff09;在地址之前插…

反序列化漏洞1-PHP序列化基礎概念(0基礎超詳細)

一.PHP序列化基礎概念首先當我們看到反序列化漏洞這個概念&#xff0c;我們的第一個問題是什么是反序列化&#xff1f;那么我們要知道什么是反序列化就要知道什么是序列化。序列化就是可以將一個對象壓縮并格式化成字符串&#xff0c;可以將該對象保存下來&#xff0c;以便存儲…

【微服務】Ocelot微服務網關

目錄 一、目的 二、Ocelot介紹 三、.Net中使用Ocelot搭建網關服務 3.1 搭建網關Ocelot步驟 3.1.1、創建Net7 WebApi服務 3.1.2、Nuget引入-Ocelot程序包&#xff08;版本&#xff1a;19.0.2&#xff09; 3.1.3、配置中間件和IOC注冊 3.1.4 配置文件編輯Ocelot網關配置信…

零基礎入門:用按鍵精靈實現視頻自動操作(附完整腳本)

摘要&#xff1a;本文手把手教你編寫視頻平臺的自動化腳本&#xff0c;涵蓋點擊、循環、防檢測等核心技巧&#xff0c;無需編程基礎&#xff0c;輕松實現自動播放/點贊/跳過廣告。&#xff08;使用按鍵精靈2024版演示&#xff09; 一、應用場景 自動化操作&#xff1a;自動跳過…