星空网 > 软件开发 > Java

java之前往对象村

这次说一说面向对象与面向过程的区别以及面向对象的优点。


java之前往对象村

  // make the shape rotate 360º

}

playSound(shapeNum) {

  // use shapeNum to lookup which

     // AIF sound to play, and play it

 

 

}

 

 

我思考很久,也找到了其中的类:图形。(哈哈)

继续按着面向对象的思想思索,这个类有什么属性呢?需求里没提吧。类的行为呢?有旋转,和放音乐的行为。嗯,分析完就写程序啦。

class cirlce {

  ratate() {

    //code to ratate a circle

     }

  playSound() {

    //code to ratate a circle

  }

}

 

class Square {

 

  ratate() {

 

    //code to ratate a circle

 

     }

 

  playSound() {

 

    //code to ratate a circle

 

  }

 

 

 

 

 

 

 

 

 

 

现在项目经理说需求有变

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

面向对象三大特性中的:继承,多态,让代码的复用率提高了老多。

面向对象优点非常非常的多,自己可以去深深体验一下,编程学习中自己尝试是非常非常重要的。


 

一个小建议:

If you’re stuck on an exercise, try talking about it out loud. Speaking (and hearing) activates a different part of your brain. Although it works best if you have another person to discuss it with, pets work too. That’s how our dog learned polymorphism.

java之前往对象村




原标题:java之前往对象村

关键词:JAVA

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流