這是自己做的練習,可能有錯誤,歡迎討論和各種最佳化重構方案。
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