发明该软件是因为它需要一种快速轻松地增加机器行为的方法。如果我们不能使系统灵活地改变,我们就完全错过了我们的目的。
一个所有的软件系统都可以分解为两大元素:
-
政策:所有业务规则和程序。系统的真正价值在这里存在;
-
详细信息:与策略通信所必需的东西,但根本不影响策略的行为(I/O 设备、数据库、框架、协议……);
因此,我们可以将软件架构的定义总结为:
“软件架构是帮助我们设计政策的学科,以便可以尽可能长时间地延迟和推迟有关细节的决策”
3. 什么是面向对象编程(OOP)
这个问题的一个常见答案是“一种模拟现实世界的方法。” 但这充其量只是一个回避的答案……。
另一个普遍的答案依赖于 3 个神奇的词来解释 OO 的本质:“封装”、“继承”和“多态”
……这些都是 OOP 范式的真正特点吗p>
-
完美 的封装也出现在像C这样的非 OO 语言中,这要归功于头文件 ( .h ) 的明智使用:我们预先在头文件中声明数据结构和函数,然后在实现文件中实现它们。我们的用户永远无法访问这些实现文件中的元素;
-
借助一个技巧,继承也可以在 C 中获得:
函数getchar()可以这样实现:
The main problem here is the incorrect usage of inheritance that violates LSP. To overcome the problem we could (mistakenly) start defining additional mechanisms for the client to understand the actual nature of the shape and act accordingly (if isSquare(r) then …). This has a devastating long-term negative impact and we should see that LSP has been breached.
Solution:
We need to redesign the interaction of the client-server modules creating polymorphic relations compliant with LSP principle, making the client independent from the subtypes of the server module:

In this way, the code in User will never have to be specific to Square or Rectangle to calculate the area and will not be subject to changes and increases in complexity if we introduce new subtypes (e.g. Circle).
文章知识点与官方知识档案匹配,可进一步学习相关知识Java技能树首页概览93576 人正在系统学习中
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!