錯誤的 oo 概念
昨天看了很多同學的 java 功課…發覺大家根本不知道何謂 oo
無他,因為老師都是這樣灌輸錯誤的訊息給我們。
好不容易才找回這兩篇文章:
http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html
http://www.javaworld.com/javaworld/jw-01-2004/jw-0102-toolbox.html
該文章解釋了 getter/setter methods 不應該出現在 oo 中,因為 oo 的真義是要實行 implementation hiding.
小弟認為文中最精警的一句:
Don’t ask for the information you need to do the work; ask the object that has the information to do the work for you.
但學校的 notes, lab, 某些同學所做的功課,偏偏要為每個 attribute 寫 getter 及 setter, 簡直多此一舉。
加長程式長度之餘,又使程式更難維護 (因做不到 implementation hiding),這些都不是 oo 的原意。明明百多行便可完成,偏偏要寫數百行,何必呢?
No Comments »
RSS feed for comments on this post. TrackBack URL
Leave a comment
You must be logged in to post a comment.