面向对象的软件设计原则

发布于 2024-07-26 04:38:33 字数 249 浏览 2 评论 0原文

我非常喜欢SOLIDDRY等软件设计原则。 OO 软件设计还存在哪些其他原则?

笔记。 我不是在寻找“评论你的代码”之类的答案,而是寻找像 鲍勃叔叔。

I am a huge fan of software design principles such as SOLID and DRY. What other principles exist for OO software design?

Note. I’m not looking for answers like "comment your code" but instead looking for OO design principles like the ones discussed by Uncle Bob.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

讽刺将军 2024-08-02 04:38:34

维基百科上的一个相当全面的列表:

http://en.wikipedia.org/wiki/List_of_software_development_philosophies

  • 软件开发
  • 敏捷统一流程 (AUP)
  • 行为驱动开发 (BDD)
  • 预先大设计 (BDUF)
  • 布鲁克斯定律
  • 大教堂和集市
  • 代码和修复
  • 构造主义设计方法 (CDM)
  • 牛仔编码
  • 水晶般清晰
  • 设计驱动开发 (D3)
  • 不重复自己 (DRY) 或一次且仅一次 (OAOO)、单点真理 (SPoT)
  • 动态系统开发方法 (DSDM)
  • 极限编程 (XP)
  • 功能驱动开发
  • 好莱坞原理
  • 迭代和增量开发
  • 联合应用程序设计,又名 JAD 或“联合应用程序开发”
  • Kaizen
  • 看板
  • KISS 原则(保持简单、愚蠢)
  • 精益软件开发
  • Microsoft 解决方案框架 (MSF)
  • 模型驱动架构 (MDA)
  • 开源
  • 开放统一流程
  • 快速而简单的
  • Rational 统一流程 (RUP)
  • Scrum
  • 智能 (敏捷开发)
  • 关注点分离 (SoC)
  • 面向服务的建模
  • 软件工艺
  • 软件系统安全
  • 螺旋模型
  • 测试驱动开发 (TDD)
  • 统一过程 (UP)
  • V 模型
  • 瀑布模型
  • 轮辐模型
  • 越差越好(新泽西风格,如与麻省理工学院的方法对比)
  • Xtreme
  • You Ain't Gonna Need It (YAGNI)
  • 零一无限

A fairly comprehensive list from Wikipedia:

http://en.wikipedia.org/wiki/List_of_software_development_philosophies

  • Agile software development
  • Agile Unified Process (AUP)
  • Behavior Driven Development (BDD)
  • Big Design Up Front (BDUF)
  • Brooks's law
  • Cathedral and the Bazaar
  • Code and fix
  • Constructionist design methodology (CDM)
  • Cowboy coding
  • Crystal Clear
  • Design-driven development (D3)
  • Don't repeat yourself (DRY) or Once and Only Once (OAOO), Single Point of Truth (SPoT)
  • Dynamic Systems Development Method (DSDM)
  • Extreme Programming (XP)
  • Feature Driven Development
  • Hollywood Principle
  • Iterative and incremental development
  • Joint application design, aka JAD or "Joint Application Development"
  • Kaizen
  • Kanban
  • KISS principle (Keep It Simple, Stupid)
  • Lean software development
  • Microsoft Solutions Framework (MSF)
  • Model-driven architecture (MDA)
  • Open source
  • Open Unified Process
  • Quick-and-dirty
  • Rational Unified Process (RUP)
  • Scrum
  • Smart (agile development)
  • Separation of concerns (SoC)
  • Service-oriented modeling
  • Software Craftsmanship
  • Software System Safety
  • Spiral model
  • Test-driven development (TDD)
  • Unified Process (UP)
  • V-Model
  • Waterfall model
  • Wheel and spoke model
  • Worse is better (New Jersey style, as contrasted with the MIT approach)
  • Xtreme
  • You Ain't Gonna Need It (YAGNI)
  • Zero One Infinity
沙与沫 2024-08-02 04:38:34

高内聚 - 您正在设计的模块的职责有多集中。

低耦合 - 模块依赖其他模块的程度。

High Cohesion - How focused are the responsibilities of the modules you are designing.

Low Coupling - The degree to which modules rely on other modules.

何必那么矫情 2024-08-02 04:38:34

选择组合而不是继承,就是其中之一。

许多人,尤其是那些刚刚接触 OO 的人,当他们真正需要的只是使用组合时,就会开始扩展类。 真的,如果你问自己,新的B班是A班吗? 如果不是,那么你不应该延长。

例如,假设我有一个 Person 类、一个 Car 类,并且我想创建一个名为 DrivenCar 类的新类。 一个天真的实现会说(假设我们有多重继承)

class DrivenCar extends Person, Car  { ... }

DrivenCar 是 Person 的类型吗? 不,所以它不应该扩展 Person。 DrivenCar 是汽车吗? 是的,所以

使用组合扩展实现是有意义的

class DrivenCar extends Car {
    private Person driver;
}

Chose composition over inheritance, is one.

Many people, especially those new to OO will start extending classes when all they really need to is to use composition. Really if you should ask your self, is the new class B a Class A? If not then you shouldn't extend.

For example, let's say I have a Person Class, a Car Class, and I would like to make a new class called a DrivenCar class. A naive implementation would be to say (let's pretend we got multiple inheritance)

class DrivenCar extends Person, Car  { ... }

Is the DrivenCar a type of Person? No so it shouldn't be extending Person. Is the DrivenCar a Car? yes so it makes sense to extend

Using composition the implmentation would look like

class DrivenCar extends Car {
    private Person driver;
}
緦唸λ蓇 2024-08-02 04:38:34

GRASP 模式。 是的,它们看起来相当微不足道。 更像是蒸馏到其他更复杂的模式所展示的核心品质。

The GRASP patterns. Yes, they seem rather trivial. More like distillation down to core qualities that other, more involved patterns demonstrate.

中二柚 2024-08-02 04:38:34

界面。 大多数设计模式都是基于界面和界面的分离。 执行。

Interface. Most design patterns are based on separation of interface & implementation.

薔薇婲 2024-08-02 04:38:34

当您的 API 预计会增长时,请使用抽象类而不是接口。 在接口中添加新方法需要更改实现它的所有类。

When your API are expected to grow, use Abstract class instead of Interface. Adding a new method in Interface requires to change ALL the classes which implement it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文