Are there any rules for OOP?

前端 未结 6 608
走了就别回头了
走了就别回头了 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 17:57

    These are concepts, not rules. There are no rules really, just decisions to make, some designs are better than others, some much better than others :-)

    There are plenty of guidelines though :-) Some are language specific (C++ is riddled with them) others are OO specific. Too many to list though :-)

    Off the top of my head, important ones are:

    • Loose coupling, high cohesion
    • Write testable classes, which you test
    • Use inheritence sparingly and only where it makes sense (prefer composition)
    • Try stick to the open/close principle.
    • (most important) KISS

    Plenty to expand upon and add :-)

    EDIT: I should add, the rules which you listed are not unique to OO

提交回复
热议问题