TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Module Oriented Programming: An OOP Alternative?

2 点作者 Floopsy超过 12 年前

1 comment

sparkie超过 12 年前
Either I'm lacking sleep, or this is really silly.<p>1. The key thing you don't seem to understand about OOP is that it decouples actual data ("Floopsy", 38) from the meaning of the data (name, age). The meaning can be applies across all conceivable 'instances' of a Rabbit. However, you appear to have tightly coupled a "Floopsy",38 and Rabbit. How would you define another rabbit "Flapsy", and not have a conflict with the name "Rabbit". How are you going to create new rabbits given an external data source?<p>2. Your example is flawed here, because you would use composition over inheritance for this in OOP anyway. Inheritance should be used <i>only</i> for "is-a" relationships. If you've been using it for "has-a" relationship - throw away whichever book told you to do so.<p>4. With the loss of abstraction, you lose <i>polymorphism</i> - the ability to use the same piece of code on different types. Either that, or your language will use duck typing - now you have another problem.<p>5. Your ScoreCard module here is doing exactly the same as a static class, or class with all static fields would be doing anyway - you've not solved any problem - it's just polishing global state in a pretty box.
评论 #4595942 未加载