这是自己做的练习,可能有错误,欢迎讨论和各种优化重构方案。

13-1.
程序设计。请列举一些面向对象编程与传统旧的程序设计形式相比的先进之处。
【答案】
面向对象编程(Object Oriented Programming,OOP,面向对象程序设计)是一种计算机编程架构。OOP的一条基本原则是计算机程序是由单个能够起到子程序作用的单元或对象组合而成。OOP达到了软件工程的三个主要目标:重用性、灵活性和扩展性。为了实现整体运算,每个对象都能够接收信息、处理数据和向其它对象发送信息。
【注】
答案摘抄自百度百科。

13-2.
函数和方法的比较。函数和方法之间的区别是什么?
Functions versus Methods. What are the differences between functions and methods?
【注】
在网上对这个问题有很多讨论(有的很有趣,比如提到猫和cat),如果用英文关键词搜索,答案亦很多。我的答案摘抄自本题【参考】部分的第一个链接。
【答案】
A function is a piece of code that is called by name. It can be passed data to operate on (ie. the parameters) and can optionally return data (the return value).

All data that is passed to a function is explicitly passed.

A method is a piece of code that is called by name that is associated with an object. In most respects it is identical to a function except for two key differences.

1. It is implicitly passed the object for which it was called

2. It is able to operate on data that is contained within the class (remembering that an object is an instance of a class - the class is the definition, the object is an instance of that data)

【参考】
http://stackoverflow.com/questions/155609/what-is-the-difference-between-a-method-and-a-function
http://www.wellho.net/mouth/900_Python-function-v-method.html

posted on 2012-08-31 10:17  balian  阅读(946)  评论(1编辑  收藏  举报