zoukankan      html  css  js  c++  java
  • clean architecture 读书笔记

    The goal of software architecture is to minimize the human resources required to build and maintain the required system.
    
    架构设计的目标: 用最小的人力来开发并维护需要的系统。
    
    Every software system provides two different values to the stakeholders: behavior and structure.
    软件提供两种价值:行为和结构
    行为:软件需要满足要求,能够工作。
    结构:软件需要便于改变,够“软”
    
    编程范式:
    structured programming
    object-oriented programming
    functional programming
    
    structured programming
    结构化编程
    functional decomposition 划分规模合理的程序块,各程序块完成相应部分任务,组合完成整体任务。
    create falsifiable units of programming 构建可证伪的程序块,便于测试。
    
    Certain uses of goto statements prevent modules from being decomposed recursively into smaller and smaller units, thereby preventing use of the divide-and-conquer approach necessary for reasonable proofs.
    Goto语句的使用,会妨碍将程序分解为更小的模块,进而妨碍程序的分治和并归过程。对软件架构不利。因此不被推荐使用。
    
    object-oriented programming
    面向对象编程
    
    Object, the combination of data and function. Object-oriented, a way to model the real world.
    对象:数据和功能的结合体。
    
    encapsulation, inheritance, and polymorphism
    特点:封装,继承,多态
    
    Part 2 Design Principles
    
    Single Responsibility Principle (SRP)
    A module should be responsible to one, and only one, actor. 
    一个模块应该只扮演一个角色,负责一种工作
    
    Open-Closed Principle (OCP) 
    A software artifact should be open for extension but closed for modification.
    软件架构应该便于同类扩展,同时
    
    Liskov Substitution Principle (LSP)
    
    The Interface Segregation Principle (ISP)
    
    The Dependency Inversion Principle (DIP)
    
    
    
    依赖关系
    原则:
    The outer circles are mechanisms. The inner circles are policies.
    外圈是实现,内圈是设计
    
    This rule says that source code dependencies can only point inwards. Nothing in an inner circle can know anything at all about something in an outer circle. 
    依赖是由内向外单向的。内圈不存在对外圈的依赖。
    
    Entities
    Entities encapsulate enterprise wide business rules.
    实体层:领域实体,封装了领域对象在软件中最抽象/一般化、高层次的规则。
    这部分最不容易变更或受系统其它部分的影响。
    如领域对象有哪些属性,有哪些行为。
    
    Use Cases
    The software in this layer contains application specific business rules.
    用例层:包含了软件功能相关的业务规则。
    如何操作/修改/组装领域对象(entities),完成特定目的。
    
    Interface Adapters
    a set of adapters that convert data from the format most convenient for the use cases and entities, to the format most convenient for some external agency
    接口适配器层: 数据转换,将数据在便于use case层使用的格式和便于外层模块(Frameworks and Drivers)使用的格式之间进行转换。
    如: MVC中的Controller,Gateways, Presenters
    
    Frameworks and Drivers
    The outermost layer is generally composed of frameworks and tools such as the Database, the Web Framework, etc
    框架和驱动层:各种工具、库的使用,所有具体细节的实现
    如:DB, Devices, Web, UI, External Interfaces
    
    
    设计上,依循DDD相关设计原则,采用Clean Architecture和微服务的架构,进行架构方面的设计。
    
    实现上,用Gradle构建Spring Boot项目,使用Kotlin + Arrow库来函数式编程,力求实现清晰的语义和良好的代码结构。通过Docker打包,最终部署在aws的kubenates集群上。
    
    用Gradle构建,强制分模块并用Clean Architecture架构按层分包,来约束开发人员实践DDD和Clean Architecture。
    
    Kotiln 面向开发者的JVM语言,提供相较于java更多的改进功能(Nullable Safety, coroutine, fp)和语法糖(scope method, sealed class, immutable object)
    Arrow Kotlin 实现的FP库,提供更清晰的语义(Either,Validate,fx)和良好的方法封装等,能写出更优雅的代码
    
    Spring Boot框架 主要是web应用。
    
    在spring repository的基础上二次封装,使Repository提供Domain和Dto之间的转化。让开发者尽可能的把精力放在业务实现上。
    
    测试上,单元测试,集成测试,合约测试等。mockito, mockk, pact等。
    
    
    好处:
    良好的架构,层次逻辑清晰,便于上手。
    开发的时候,便于TDD开发。各模块各层的测试好写,只关注模块功能就够了,对于其他代码依赖也更方便用依赖反转(dependency inversion)的方式进行隔离。测试好写,覆盖全面,前期好开发,后期改动时出错的可能性也更小了。
    业务上有改动,也能尽量减少需要修改的部分。(信息隔离,各模块只从其他模块获取必需的数据而非全部数据)
    技术栈的改动,也因为有各良好的结构,把工作量尽量控制到最小。(数据库的替换只用改repository,UI的替换只涉及前端)
    需要实现multi tenant,multi teant 共用一个application server,就需要隔离各tenant之间的信息。使用kotlin提供的immutable object 和 FP能够减少人出错的可能性。
    
    
    
  • 相关阅读:
    民5需求水平
    Codeforces Beta Round #3 A. Shortest path of the king
    UFLDL接听教程练习(来自编码器和矢量编程疏)
    与我一起extjs5(09--其定义菜单2)
    C++ 堆 和 堆 分析
    Spark Executor Driver资源调度汇总
    通知中心
    Objective-c正确的写法单身
    OpenCV视频播放方法
    设备11g_rac配置对等
  • 原文地址:https://www.cnblogs.com/cnsec/p/13547546.html
Copyright © 2011-2022 走看看