开发者

What's the most used philosophy of keeping independent concepts separate in OOP? [closed]

开发者 https://www.devze.com 2022-12-24 11:27 出处:网络
Closed. This question is opinion-based. It is not currently accepting answers. 开发者_开发知识库
Closed. This question is opinion-based. It is not currently accepting answers. 开发者_开发知识库

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 6 years ago.

Improve this question

Or according to your own experience,

what's your favorite trick ?


The #1 principle is encapsulation - at least the colleges have that part right.

Inheritance, polymorphism, cohesion, concision, coupling, dependency, etc... all these things really fall under that one umbrella.

"Encapsulate by practice and expose by need."

The rest pretty much proceeds from there: Limit the number of places that a change forces you to revisit, ideally, every change to behavior would either be the beginning or the end of a chain-reaction (change the test then change the thing it tests) and every change to design would trigger absolutely no consequent changes. This is a reality that is seldom achieved.

"Find what varies and encapsulate it."

Don't use inheritance to give one class the behaviors of another; use delegation in its place. Use inheritance to create abstractions behind which numerous variations live. If you think you have a problem that requires you to degrade design, your problem is probably that, instead, your design needs to improve.

There's probably a good list of OOP code qualities somewhere with good descriptions, so I won't bother to retype it here. Follow those principles, adapt your practices as your situation requires, and you should be pretty good to go.


In my CSC 110 class I was taught Homer Simpson likes PIE (PIE being the big 3 concepts of object oriented programming).

P = polymorphism I = inheritance E = encapsulation

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号