【软件设计】

2024-04-14 18:28
文章标签 软件设计

本文主要是介绍【软件设计】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

设计原则

单一职责原则Single responsibility principle(SRP)

A class should have a single purpose and only one reason to change If a class has more than one responsibility, then the responsibilities becomes coupled SRP is one of the simplest of the principles, and the one of the hardest to get right.

Heuristics

Describe the primary responsibility in a single sentence Group similar methods Look at hidden methods (private, protected) Many of them indicate that there is another class in the class tying to get out Look for decisions that can change They should go into a separate class Look for internal relationships Are certain variables used by some methods and not others?

Benefits

Easy to modularize, better organization of code Better robustness Weaker coupling Easier to reuse Better maintainability Easy to test Easy to debug

开闭原则Open closed principle(OCP)

Software entities( classes, modules, functions, etc.) should be open for extension, but closed for modification “Open for extension”:The behavior of the module can be extended (e.g., by subclassing) “Closed for modification”:Extending the behavior of a module does not result in changes to the existing source code or binary code of the module This is especially valuable in a production environment, where changes to source code may necessitate code reviews unit tests, Integration test etc., procedures

里氏代换原则Liskov Substitution principle(LSP)

子类可以随时代换父类

满足is……a……的关系

除非父类是抽象方法,子类不能重写

Subtypes must be substitutable for their base types LSP defines the OO inheritance principle If a client uses a base class, then it should not differentiate the base class from derived class, which means the derived class can substitute the base class

Interface segregation Principle(ISP)接口隔离原则

Clients should not be forced to depend on methods they do not use Design cohesive interfaces and avoid "fat" interfaces The dependency of one class to another one should depend on the smallest possible interface The interfaces of the class can be broken up into groups of methods Each group serves a different set of clients

Dependency inversion principle(DIP)依赖倒置原则

上层和下层中间应该有一个依赖层

High-level modules should not depend on low-level modules Both should depend on abstractions(抽象层) Abstractions should not depend on details Details should depend on abstractions DIP is at the very heart of framework design

Low of Demeter(LOD)迪米特法则

Principle of Least Knowledge最少知识原则 Only talk to your immediate friends Don’t talk to strangers Write “shy” codes Minimize coupling

A method M of an object O may only invoke the methods of the following kinds of objects: O itself M's parameters Any objects created/instantiated within M O's direct component objects/list

Composition reuse principle (CRP)

Composite / Aggregate Reuse Principle(CARP)

Note: some of the features if the new object has been created in other good object which has been achieved, then try to use the functionality provided by other objects to become part of the new object, rather than their own re-create. These new objects through objects have been assigned to multiplexing function. In short, to make use of synthesis / polymerization, try not to use inheritance.

Comparing composition and inheritance

方法:继承,组合(合成),

Inheritance is tightly coupled whereas composition is loosely coupled. There is no access control in inheritance whereas access can be restricted in composition. We expose all the superclass methods to the other classes having access to subclass. So if a new method is introduced or there are security holes in the superclass, subclass becomes vulnerable. Since in composition we choose which methods to use, it’s more secure than inheritance. Composition provides flexibility in invocation of methods that is useful with multiple subclass scenario. One more benefit of composition over inheritance is testing scope. Unit testing is easy in composition because we know what all methods we are using from other class.

Choosing between composition and inheritance

Make sure inheritance models the is-a relationship Don't use inheritance just to get code reuse Don't use inheritance just to get at polymorphism

设计模式

Creational Design Patterns

Creational design patterns abstract the instantiation process. There are two recurring themes in these patterns.

  1. they all encapsulate knowledge about which concrete classes the system uses.
  2. they hide how instances of these classes are created and put together.

单例模式singleton model Pattern

工厂模式Factory model Pattern

Building Design Pattern

结构模式structural Design Patterns

Adapter design pattern

Intent

Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. Wrap an existing class with a new interface. Impedance match an old component to a new system

桥接模式Bridge design pattern

解决类爆炸

将实现和抽象分离

Decouple an abstraction from its implementation so that the two can vary independently. Publish interface in an inheritance hierarchy, and bury implementation in its own inheritance hierarchy. Beyond encapsulation, to insulation

"Hardening of the software arteries" has occurred by using subclassing of an abstract base class to provide alternative implementations. This locks in compile-time binding between interface and implementation. The abstraction and implementation cannot be independently extended or composed.

bstraction (abstract class) It defined the abstract interface i.e. behavior part. It also maintains the Implementer reference. RefinedAbstraction (normal class) It extends the interface defined by Abstraction. Implementer (interface) It defines the interface for implementation classes. This interface does not need to correspond directly to abstraction interface and can be very different. Abstraction imp provides an implementation in terms of operations provided by Implementer interface. ConcreteImplementor (normal class) It implements the Implementer interface.

装饰设计模式Decorator design pattern

Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. Client-specified embellishment of a core object by recursively wrapping it. Wrapping a gift, putting it in a box, and wrapping the box.

代理设计模式Proxy design pattern

Provide a surrogate or placeholder for another object to control access to it. Use an extra level of indirection to support distributed, controlled, or intelligent access. Add a wrapper and delegation to protect the real component from undue complexity.

You need to support resource-hungry objects, and you do not want to instantiate such objects unless and until they are actually requested by the client.

外观模式Facade Design Pattern

组合模式Composite Design Pattern

行为模式Behavior Design Patterns

Chain of Responsibility design pattern责任链

命令模式Command Design Pattern

模板方法模式Template Method Design Pattern

策略模式Strategy design pattern

观察者模式Observer Design Pattern

这篇关于【软件设计】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/903674

相关文章

三十八篇:架构大师之路:探索软件设计的无限可能

架构大师之路:探索软件设计的无限可能 1. 引言:架构的艺术与科学 在软件工程的广阔天地中,系统架构不仅是设计的骨架,更是灵魂所在。它如同建筑师手中的蓝图,决定了系统的结构、性能、可维护性以及未来的扩展性。本节将深入探讨软件架构的定义、其在系统设计中的核心作用,以及不同架构风格对系统特性的影响。 软件架构的定义及其在系统设计中的核心作用 软件架构,简而言之,是指软件系统的基本组织结构,

【软件设计】详细设计说明书(word原件,项目直接套用)

软件详细设计说明书 1.系统总体设计 2.性能设计 3.系统功能模块详细设计 4.数据库设计 5.接口设计 6.系统出错处理设计 7.系统处理规定 软件全套资料:本文末个人名片直接获取或者进主页。

【软考系统架构设计师】四、嵌入式基础知识(软件|软件设计|硬件|式总线逻辑)

目录 一、嵌入式软件 1.1 嵌入式软件分类 1.2 板级支持包(BSP) 1.3 BootLoader 1.4 设备驱动程序 二、嵌入式软件设计 2.1 编码 2.2 交叉编译 2.3 交叉调试 三、嵌入式系统硬件的分类 3.1 根据用途分类 3.2 存储器分类 四、内(外)总线逻辑 五、历年真题练习 一、嵌入式软件         嵌入式软件是指应用在嵌

软件设计模式,给你解决问题的标准答案,少走弯路

设计模式简介 软件设计模式,是前辈们在重复发生的特定问题中总结出的解决方案,具有一定的普遍性,可以反复使用。 目的是为了提高代码的可重用性、代码的可读性和代码的可靠性;是开发者们快速成长的捷径。 强烈建议大家对设计模式进行学习,并融入到项目当中去。 设计模式针对的都是面向对象的编程语言,如java/C#等。设计模式适用于大型的项目或者框架开发,简单的项目就没必要强行使用了,不然反而适得其反。

从软件设计角度下的操作系统发展轨迹——From the perspective of the software design of operating system course

操作系统首先是一个软件,它的设计脱离不了软件设计的范畴。从纯软件发展的角度对其进行考察,有助于我们了解操作系统的历史。下表给出了软件设计角度下的操作系统发展轨迹。     主流操作系统 系统特点 计算机语言 软件特点 背  景 无软件时期 无 手工操作 无编程语言,直接使用机器代码 手工操作 1936年图灵提出图灵机模型 系

基于安卓的虫害识别软件设计--(2)模型性能可视化|混淆矩阵、热力图

1.混淆矩阵(Confusion Matrix) 1.1基础理论 (1)在机器学习、深度学习领域中,混淆矩阵常用于监督学习,匹配矩阵常用于无监督学习。主要用来比较分类结果和实际预测值。 (2)图中表达的含义:混淆矩阵的每一列代表了预测类别,每一行代表了数据的真实类别。 1.2 实现代码 import torchimport osfrom PIL import Imageimpo

软件设计---UML,统一建模语言

UML图的分类 静态模型 创建并记录一个系统的静态特征。 反映一个软件系统基础、固定的框架结构。 创建相关问题域主要元素的视图。 静态建模包括: 用例图 展示系统的核心功能及与其监护的用户,用户被称之为"活动者",用例使用椭圆标识,为简化建模过程,用例图可标注优先级。 用例图展示: 创建用例图: 导出用例图: 类图 表现类的特征,描述各个领域之间的关系。 类图

软件设计---抽象类与接口

抽象类 通常是一类事物的公共部分的抽象   简单的说    我要开发一个“门”    但是是什么门?  这个时候  大伙都不清楚,因为这就是一个门的概念    但是既然是开发门  那么我们要开发什么门?  实木门? 大铁门? 但是 不管是实木门还是大铁门  首先它是一个门   这就是对同类事物公共部分的抽象   但是那为什么不把门定义成一个接口呢?     原因很简单      "类"   是描

软件设计是怎样炼成的?-张传波-专题视频课程

软件设计是怎样炼成的?—34792人已学习 课程介绍         软件设计视频培训教程,该课程告诉大家,软件设计并不是概要设计与详细设计这么简单,更加不是纸上谈兵的事情。课程全程活用UML(统一建模语言或标准建模语言),为你分享架构设计、数据库设计、用户体验设计和详细设计的实战技巧,并附上实战案例,软件设计文档撰写、工具使用。让你学会如何分析需求,如何逐步做出“漂亮”的软件设计

软件设计中的数字:7

“ 使软件更易理解的秘密:米勒法则” 小游戏 学习之前先一起玩一个小游戏。 3秒钟时间,看看下面的图片中有多少个小块? 3秒到了,数出来了吗?22个。 没数出来也没关系,我也没数出来o(╥﹏╥)o 现在,我对上面的小方块施一下魔法,重新再来一遍,还是3秒。 准备,开始! 这次怎么样?数出22这个数字了吗?还是6、10、6这几个数字? 神奇吗? 其实这就是米勒法则的魔力。 今日