Are there any rules for OOP?

前端 未结 6 610
走了就别回头了
走了就别回头了 2020-11-29 17:17

Recently I heard that there are 9 rules for OOP(Java). I know only four as Abstraction, Polymorphism, Inheritance and Encapsulation. Are there any more rules for OOP?

6条回答
  •  庸人自扰
    2020-11-29 18:13

    These OO principles are straight from Head First Design Patterns:

    • Encapsulate what Varies
    • Program to an Interface, rather than an Implementation
    • Favour Composition over Inheritance
    • A Class should have only one reason to Change (Single Responsibility Principle)
    • Sub-Types must be substitutable for their Base (Liskov Substitition Principle)
    • Classes shoule be Open for extension, but Closed for Modification (Open-Closed Principle)

提交回复
热议问题