可靠的广州做网站/app地推网

可靠的广州做网站,app地推网,福建省漳州市政府网站建设情况,faq页面设计模板What Is Architecture?&Independence **Chapter 15: What Is Architecture?****Key Concepts**:**Code Example: Layered Architecture**: **Chapter 16: Independence****Key Concepts**:**Code Example: Dependency Inversion & Interfaces**: **Combined Example:…

What Is Architecture?&Independence

      • **Chapter 15: What Is Architecture?**
        • **Key Concepts**:
        • **Code Example: Layered Architecture**:
      • **Chapter 16: Independence**
        • **Key Concepts**:
        • **Code Example: Dependency Inversion & Interfaces**:
      • **Combined Example: Boundaries & Independence**
      • **Key Takeaways**:
      • **Chapters 15 & 16 Overview**
      • **10 Hard Difficulty Multiple-Choice Questions**
      • **Test Code Examples**


Chapter 15: What Is Architecture?

Key Concepts:
  1. Definition: Architecture is the shape of a system defined by components, dependencies, and boundaries that manage complexity and enable evolution.
  2. Core Goals:
    • Manage Complexity: Decouple components to isolate changes.
    • Keep Options Open: Delay decisions (e.g., frameworks, databases) to avoid premature constraints.
    • Support Use Cases: Ensure the system delivers business value.
  3. Layers & Boundaries:
    • Separate high-level policy (business logic) from low-level details (I/O, UI).
    • Use boundaries (interfaces, abstractions) to isolate volatile components.
Code Example: Layered Architecture:
#include <iostream>
#include <string>
#include <vector>// High-level Policy (Business Logic)
class Order {
public:virtual double calculateTotal() const = 0;virtual ~Order() = default;
};// Low-level Detail (Implementation)
class ConcreteOrder : public Order {
private:std::vector<double> items;
public:void addItem(double price) { items.push_back(price); }double calculateTotal() const override {double total = 0;for (auto price : items) total += price;return total;}
};// Client Code (Depends on Abstraction)
void printTotal(const Order& order) {std::cout << "Total: $" << order.calculateTotal() << std::endl;
}int main() {ConcreteOrder order;order.addItem(10.5);order.addItem(20.3);printTotal(order); // Output: Total: $30.8return 0;
}

Explanation:

  • Abstraction: Order is an interface defining business rules.
  • Implementation: ConcreteOrder provides the calculation logic.
  • Dependency Inversion: printTotal depends on the abstract Order, not concrete details.

Chapter 16: Independence

Key Concepts:
  1. Component Independence:
    • Deployability: Components can be deployed separately (e.g., microservices).
    • Developability: Teams work independently on components.
    • Replaceability: Swap implementations without breaking the system.
  2. Decoupling Techniques:
    • Dependency Inversion: Depend on abstractions, not concretions.
    • Interface Segregation: Split interfaces to avoid unnecessary dependencies.
    • Boundary Patterns: Use layers, ports/adapters, or hexagonal architecture.
Code Example: Dependency Inversion & Interfaces:
#include <iostream>
#include <memory>// Abstraction (Port)
class Database {
public:virtual void save(const std::string& data) = 0;virtual ~Database() = default;
};// Low-level Detail (Adapter)
class SQLDatabase : public Database {
public:void save(const std::string& data) override {std::cout << "Saving to SQL: " << data << std::endl;}
};// High-level Policy
class UserService {
private:std::unique_ptr<Database> db;
public:UserService(std::unique_ptr<Database> db) : db(std::move(db)) {}void createUser(const std::string& name) {db->save("User: " + name);}
};int main() {auto sqlDb = std::make_unique<SQLDatabase>();UserService service(std::move(sqlDb));service.createUser("Alice"); // Output: Saving to SQL: User: Alicereturn 0;
}

Explanation:

  • Dependency Inversion: UserService depends on the Database abstraction.
  • Testability: Easily swap SQLDatabase with a MockDatabase for testing.
  • Decoupling: Changes to the database implementation don’t affect UserService.

Combined Example: Boundaries & Independence

#include <iostream>
#include <memory>// Port (Interface)
class PaymentGateway {
public:virtual void pay(double amount) = 0;virtual ~PaymentGateway() = default;
};// Adapter 1: PayPal Implementation
class PayPalGateway : public PaymentGateway {
public:void pay(double amount) override {std::cout << "Paying $" << amount << " via PayPal." << std::endl;}
};// Adapter 2: Stripe Implementation
class StripeGateway : public PaymentGateway {
public:void pay(double amount) override {std::cout << "Paying $" << amount << " via Stripe." << std::endl;}
};// High-level Policy
class OrderService {
private:std::unique_ptr<PaymentGateway> gateway;
public:OrderService(std::unique_ptr<PaymentGateway> gateway) : gateway(std::move(gateway)) {}void processOrder(double amount) {gateway->pay(amount);}
};int main() {// Swap payment gateways without changing OrderService.auto paypal = std::make_unique<PayPalGateway>();OrderService service1(std::move(paypal));service1.processOrder(100.0); // Output: Paying $100 via PayPal.auto stripe = std::make_unique<StripeGateway>();OrderService service2(std::move(stripe));service2.processOrder(200.0); // Output: Paying $200 via Stripe.return 0;
}

Explanation:

  • Boundary: PaymentGateway defines a port for payment processing.
  • Independence: OrderService is decoupled from specific payment providers.
  • Flexibility: New gateways (e.g., BitcoinGateway) can be added without modifying core logic.

Key Takeaways:

  1. Architecture = Managed Dependencies: Use abstractions to isolate volatility.
  2. Delay Decisions: Keep infrastructure (databases, UIs) replaceable.
  3. Test with Mocks: Compile-time polymorphism enables testing without concrete dependencies.

Chapters 15 & 16 Overview

Chapter 15: “What Is Architecture?”

  • Focuses on defining architecture as the structure of components, their relationships, and design principles guiding evolution.
  • Key topics:
    1. Architectural goals: Managing dependencies between components, enabling flexibility, and delaying decisions.
    2. Impact on development phases: Deployment, operation, maintenance, and evolution.
    3. Device independence and avoiding premature commitment to frameworks/databases.

Chapter 16: “Independence”

  • Discusses designing systems to achieve independent components for flexibility and scalability.
  • Key topics:
    1. Horizontal vs. vertical decoupling: Separating use cases, layers (UI, business logic, data).
    2. Delaying decisions: Keeping options open by abstracting volatile components (e.g., databases).
    3. Avoiding duplication while balancing decoupling.

10 Hard Difficulty Multiple-Choice Questions

Question 1
Which are core goals of software architecture according to Chapter 15?
A) Maximize code performance.
B) Delay irreversible decisions.
C) Enforce strict coding standards.
D) Manage dependencies between components.


Question 2
What does “device independence” imply in Clean Architecture?
A) Code must run on all hardware without modification.
B) Business logic should not depend on specific I/O devices or frameworks.
C) Use cross-platform libraries for all components.
D) Avoid using third-party APIs.


Question 3
Which principle helps achieve independent deployability of components?
A) Stable Dependencies Principle.
B) Interface Segregation Principle.
C) Single Responsibility Principle.
D) Common Closure Principle.


Question 4
Why is horizontal layering insufficient for true independence?
A) It enforces rigid dependencies between layers.
B) It doesn’t address vertical use-case boundaries.
C) It increases deployment complexity.
D) It violates the Open-Closed Principle.


Question 5
How does Clean Architecture handle database dependencies?
A) Business logic directly depends on SQL queries.
B) Database access is abstracted via interfaces.
C) Use a single global database connection.
D) Business logic and database are tightly coupled.


Question 6
Which is a valid strategy to delay decisions?
A) Hardcoding configuration values.
B) Using dependency injection for volatile components.
C) Relying on concrete framework APIs.
D) Embedding business rules in UI code.


Question 7
What is the risk of violating the Stable Dependencies Principle?
A) High-level policies depend on low-level details.
B) Components cannot be tested independently.
C) Changes propagate unpredictably across the system.
D) Code duplication increases.


Question 8
Which code snippet aligns with Clean Architecture principles?
Snippet 1:

class PaymentProcessor:def __init__(self, db_conn):self.db = db_conndef process(self, amount):self.db.execute("INSERT INTO payments ...")

Snippet 2:

class PaymentGateway(ABC):@abstractmethoddef process_payment(self, amount): passclass SqlPaymentGateway(PaymentGateway):def __init__(self, db_conn): ...def process_payment(self, amount): ...

A) Only Snippet 1.
B) Only Snippet 2.
C) Both.
D) Neither.


Question 9
What problem arises when business logic depends on UI frameworks?
A) UI changes force business logic rewrites.
B) Business logic becomes reusable across UIs.
C) It simplifies testing.
D) It improves deployment speed.


Question 10
Which is an example of vertical decoupling?
A) Separating code into MVC layers.
B) Isolating payment processing from user management.
C) Using interfaces for database access.
D) Implementing a plugin architecture.


Answers & Explanations

Answer 1
Correct: B, D
Explanation:

  • B) Delaying decisions prevents premature commitments (Ch15).
  • D) Managing dependencies is a core architectural goal (Ch15).
  • A) Performance is secondary to structural goals.
  • C) Coding standards are implementation details, not architectural goals.

Answer 2
Correct: B
Explanation:

  • B) Device independence means business logic isn’t tied to specific I/O (Ch15).
  • A) Code may require device-specific drivers but abstracts them.
  • C/D) Irrelevant to the core concept.

Answer 3
Correct: A
Explanation:

  • A) Stable Dependencies Principle ensures components depend only on stable abstractions (Ch16).
  • B/C/D) Address cohesion or interface design, not deployability.

Answer 4
Correct: B
Explanation:

  • B) Horizontal layers (e.g., UI, business logic) don’t isolate use cases vertically (Ch16).
  • A) Rigid dependencies are a symptom, not the root cause.

Answer 5
Correct: B
Explanation:

  • B) Abstracting database access via interfaces decouples business logic (Ch15).
  • A/C/D) Create tight coupling and violate independence.

Answer 6
Correct: B
Explanation:

  • B) Dependency injection defers concrete implementation choices (Ch16).
  • A/C/D) Fix decisions early, reducing flexibility.

Answer 7
Correct: A, C
Explanation:

  • A) High-level components depending on low-level details creates fragility.
  • C) Violations cause cascading changes (Ch16).
  • B/D) Unrelated to dependency stability.

Answer 8
Correct: B
Explanation:

  • Snippet 2 uses abstraction (PaymentGateway), aligning with DIP (Ch11/15).
  • Snippet 1 directly depends on a database, violating decoupling.

Answer 9
Correct: A
Explanation:

  • A) Tight coupling forces rewrites when UI changes (Ch16).
  • B/D) Independence improves reusability and deployment.

Answer 10
Correct: B
Explanation:

  • B) Vertical decoupling isolates use cases (e.g., payment vs. user management) (Ch16).
  • A/C) Horizontal layering or interface use.
  • D) Plugin architecture is a horizontal strategy.

Test Code Examples

Example for Q8 (Snippet 2):

from abc import ABC, abstractmethodclass PaymentGateway(ABC):@abstractmethoddef process_payment(self, amount): passclass SqlPaymentGateway(PaymentGateway):def __init__(self, db_conn):self.db = db_conndef process_payment(self, amount):self.db.execute("INSERT INTO payments ...")# Test
class MockDb:def execute(self, query): print(f"Mock: {query}")gateway = SqlPaymentGateway(MockDb())
gateway.process_payment(100)  # Output: "Mock: INSERT INTO payments ..."

Compilation: This Python code runs as-is, demonstrating dependency inversion.

Example for Q5:

class DatabaseInterface(ABC):@abstractmethoddef save_payment(self, amount): passclass PostgresAdapter(DatabaseInterface):def save_payment(self, amount): ...class BusinessLogic:def __init__(self, db: DatabaseInterface):self.db = dbdef process_payment(self, amount):self.db.save_payment(amount)

Test: BusinessLogic depends on an abstraction, enabling database swaps without code changes.

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

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

相关文章

【SPP】RFCOMM 层在SPP中互操作性要求深度解析

蓝牙串口协议&#xff08;SPP&#xff09;通过 RFCOMM 协议实现 RS232 串口仿真&#xff0c;其互操作性是设备互联的关键。本文基于蓝牙核心规范&#xff0c;深度解析 RFCOMM 层的能力矩阵、信号处理、流控机制及实战开发&#xff0c;结合状态机、流程图和代码示例&#xff0c;…

Gossip协议:分布式系统中的“八卦”传播艺术

目录 一、 什么是Gossip协议&#xff1f;二、 Gossip协议的应用 &#x1f4a1;三、 Gossip协议消息传播模式详解 &#x1f4da;四、 Gossip协议的优缺点五、 总结&#xff1a; &#x1f31f;我的其他文章也讲解的比较有趣&#x1f601;&#xff0c;如果喜欢博主的讲解方式&…

【C++初阶】----模板初阶

1.泛型函数 泛型编程&#xff1a;编写与类型无关的通用代码&#xff0c;是代码复用的一种手段。模板是泛型编程的基础。 2.函数模板 2.1函数模板的概念 函数模板代表了一个函数家族&#xff0c;该函数模板与类型无关&#xff0c;在使用时被参数化&#xff0c;根据实参类型…

git-- github的使用--账户和本地连接

以下指令在git 执行bash 流程&#xff1a;先看有没有密钥&#xff1b; 没有的话&#xff0c;在电脑生成密钥对&#xff0c;公钥复制到github&#xff1b; 要想使用https&#xff0c;配置令牌&#xff0c;注意令牌有期限问题&#xff0c;连接不了有可能是期限问题 一个电脑对…

Angular由一个bug说起之十五:自定义基于Overlay的Tooltip

背景 工具提示&#xff08;tooltip&#xff09;是一个常见的 UI 组件&#xff0c;用于在用户与页面元素交互时提供额外的信息。由于angular/material/tooltip的matTooltip只能显示纯文本&#xff0c;所以我们可以通过自定义Directive来实现一个灵活且功能丰富的tooltip Overlay…

搭建QNX Software Center的Docker环境

背景 本人使用 Ubuntu Server 22.04 服务器&#xff0c;所以没有图形界面&#xff0c;而 QNX Software Center 需要图形界面。为了保证服务器环境的整理&#xff0c;计划使用Docker部署QNX Software Center 一瓶安装图形界面。本方既是实现方案的记录。 资源 Dockerfile&…

C#/.NET/.NET Core技术前沿周刊 | 第 31 期(2025年3.17-3.23)

前言 C#/.NET/.NET Core技术前沿周刊&#xff0c;你的每周技术指南针&#xff01;记录、追踪C#/.NET/.NET Core领域、生态的每周最新、最实用、最有价值的技术文章、社区动态、优质项目和学习资源等。让你时刻站在技术前沿&#xff0c;助力技术成长与视野拓宽。 欢迎投稿、推荐…

【STM32】WDG看门狗(学习笔记)

学习来源----->江协科技STM32 WDG简介 WDG&#xff08;Watchdog&#xff09;看门狗看门狗可以监控程序的运行状态&#xff0c;当程序因为设计漏洞、硬件故障、电磁干扰等原因&#xff0c;出现卡死或跑飞现象时&#xff0c;看门狗能及时复位程序&#xff0c;避免程序陷入长…

2023第十四届蓝桥杯大赛软件赛国赛C/C++ 大学 B 组(真题题解)(C++/Java题解)

本来想刷省赛题呢&#xff0c;结果一不小心刷成国赛了 真是个小迷糊〒▽〒 但&#xff0c;又如何( •̀ ω •́ )✧ 记录刷题的过程、感悟、题解。 希望能帮到&#xff0c;那些与我一同前行的&#xff0c;来自远方的朋友&#x1f609; 大纲&#xff1a; 一、子2023-&#xff…

CSS学习笔记6——网页布局

目录 一、元素的浮动属性、清除浮动 清除浮动的其他方法 1、使用空标签清除浮动影响 2、使用overflow属性清除浮动 3、使用伪元素清除浮动影响 原理 overflow属性 二、元素的定位 1、相对定位 2、绝对定位 ​编辑 3、固定定位 z-index层叠等级属性 一、元素的浮动…

Linux之数据链路层

Linux之数据链路层 一.以太网1.1以太网帧格式1.2MAC地址1.3MTU 二.ARP协议2.1ARP协议工作流程2.2ARP协议格式 三.NAT技术四.代理服务4.1正向代理4.2反向代理 五.四大层的学习总结 一.以太网 在我们学习完了网络层后我们接下来就要进入数据链路层的学习了&#xff0c;在学习完网…

MySQL的基础语法2(函数-字符串函数、数值函数、日期函数和流程函数 )

目录 一、字符串函数 1.常见字符串函数 ​编辑 2.字符串函数的基本使用 3.字符串函数的数据库案例演示 二、数值函数 1.常见数值函数&#xff08;如下&#xff09;&#xff1a; 2.数值函数的基本使用 3.数值函数的数据库案例演示 三、日期函数 1.常见的日期函数 2.日…

全新版租赁商城小程序源码系统 源码开源支持二开+图文搭建教程

在互联网商业的浪潮中&#xff0c;租赁业务凭借其独特的优势&#xff0c;正逐渐成为市场的新宠。对于开发者而言&#xff0c;快速搭建一个功能完备的租赁商城小程序&#xff0c;不仅能满足市场需求&#xff0c;还能为自己的业务拓展带来新的机遇。分享一款全新版租赁商城小程序…

Cent OS7+Docker+Dify

由于我之前安装了Dify v1.0.0&#xff0c;出现了一些问题&#xff1a;无法删除&#xff0c;包括&#xff1a;知识库中的文件、应用、智能体、工作流&#xff0c;都无法删除。现在把服务器初始化&#xff0c;一步步重新安装&#xff0c;从0到有。 目录 1、服务器重装系统和配置…

AI的未来:机遇、挑战与发展方向

&#x1f4dd;个人主页&#x1f339;&#xff1a;一ge科研小菜鸡-CSDN博客 &#x1f339;&#x1f339;期待您的关注 &#x1f339;&#x1f339; 1. 引言 人工智能&#xff08;AI&#xff09;已经成为当今世界最具革命性的技术之一&#xff0c;它正在深刻改变各个行业&#x…

使用vue cli 5.0 在vscode中运行vue命令报错

1、运行 vue -- version 报错 2、在cmd 命令行 执行 vue --version 正常 3、在终端中输入 get-ExecutionPolicy&#xff0c;查看当前权限 4、执行 set-executionpolicy remotesigned 命令设置为可用模式&#xff0c;但是报错 5、使用管理员打开power shell 执行 G…

瑞芯微 RKrga接口 wrapbuffer_virtualaddr 使用笔记

一、源码 官方在librga中给了很多 demo 以供参考&#xff0c;例如 imresize 操作&#xff1a; /** Copyright (C) 2022 Rockchip Electronics Co., Ltd.* Authors:* YuQiaowei <cerf.yurock-chips.com>** Licensed under the Apache License, Version 2.0 (the &qu…

06-SpringBoot3入门-常见注解(简介)

1、Controller ResponseBody Controller是Spring MVC 中的注解&#xff0c;负责处理 HTTP 请求。 ResponseBody是Spring MVC 中的注解&#xff0c;用于直接将方法的返回值作为 HTTP 响应体。 2、RestController RestController Controller ResponseBody 3、RequestMappin…

ubuntu24.04.2 NVIDIA GeForce RTX 4060笔记本安装驱动

https://www.nvidia.cn/drivers/details/242281/ 上面是下载地址 sudo chmod x NVIDIA-Linux-x86_64-570.133.07.run # 赋予执行权限把下载的驱动复制到家目录下&#xff0c;基本工具准备&#xff0c;如下 sudo apt update sudo apt install build-essential libglvnd-dev …

《Express:Node.js 里的 “闪电侠”》

“你就坐在我身边&#xff0c;好不好” 什么是Express 官方给出的概念&#xff1a;Express 是基于 Node.js 平台&#xff0c;快速、开放、极简的 Web 开发框架。 通俗的理解&#xff1a;Express 的作用和 Node.js 内置的 http 模块类似&#xff0c;是专门用来创建 Web 服务器…