OO Software Design Principles

2019-01-31 04:40发布

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.

8条回答
贪生不怕死
2楼-- · 2019-01-31 05:11

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;
}
查看更多
太酷不给撩
3楼-- · 2019-01-31 05:12

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
查看更多
混吃等死
4楼-- · 2019-01-31 05:16
Lonely孤独者°
5楼-- · 2019-01-31 05:18

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

查看更多
太酷不给撩
6楼-- · 2019-01-31 05:23
Animai°情兽
7楼-- · 2019-01-31 05:23

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.

查看更多
登录 后发表回答