物件導向編程

物件導向程式編寫object-oriented programmingOOP)係一種程式編寫範式(programming paradigm),指建構電腦程式嗰陣用「物件」(object)去做基本單元:個程式會有一個個嘅類別(class),每個類別會若干個實例(instance),每個物件都係一個實例,會有若干份數據,而且每件同一類別嘅物件有嘅變數都一樣[1][2]。例如以下呢段 C++ 噉:

1 class Car { // 「Car」係一個類別。
2   public: // Car 嘅每一個實例(每件屬於 Car 嘅物件)都會有以下呢啲變數...
3     string brand; // 牌子
4     string model; // 型號
5     int year; // 年份
6 };

呢種做法喺好多應用上都好幫到手令個程式更加容易打理,例:一位遊戲製作師喺度編寫佢隻新遊戲遊戲程式,佢想創造一個遊戲世界俾玩家喺裏面移動;佢想個虛擬世界設計成好似一個現實嘅城市噉,度緊個城市其中一條街要點設計,佢想條街有幾架車泊咗喺度做背景,佢可以設定一個「車」嘅類別,個類別每個實例都有「色水」同「位置」等嘅變數,然後叫個程式將「建構一個車嘅實例」呢樣嘢做三次-就唔使吓吓都重新打過「建構一個車嘅實例」嘅碼[3][4]。因為 OOP 咁好使好用,有好多常見嘅程式語言都支援 OOP,包括咗 C++JavaScriptC#Python... 等等。

睇埋

參考文獻

  • Armstrong, Deborah J. (February 2006). "The Quarks of Object-Oriented Development". Communications of the ACM. 49 (2): 123–128. doi:10.1145/1113034.1113040.
  • Pecinovsky, Rudolf (2013). OOP – Learn Object Oriented Thinking & Programming. Bruckner Publishing. ISBN 978-80-904661-8-0.
  • Schach, Stephen (2006). Object-Oriented and Classical Software Engineering, 7th Edition. McGraw-Hill. ISBN 978-0-07-319126-3.
  • Weisfeld, Matt (2009). The Object-Oriented Thought Process, 3rd Edition. Addison-Wesley. ISBN 978-0-672-33016-2.
  • West, David (2004). Object Thinking (Developer Reference). Microsoft Press. ISBN 978-0735619654.

  1. Kindler, E.; Krivy, I. (2011). "Object-Oriented Simulation of systems with sophisticated control". International Journal of General Systems: 313–343.
  2. Lewis, John; Loftus, William (2008). Java Software Solutions Foundations of Programming Design (6th ed). Pearson Education Inc. ISBN 978-0-321-53205-3., section 1.6 "Object-Oriented Programming".
  3. Quick Tip: Intro to Object-Oriented Programming for Game Development.
  4. Jacobson, Ivar (1992). Object-Oriented Software Engineering: A Use Case-Driven Approach. Addison-Wesley.