Re: [問題] 請推薦有稍微真實範例的物件導向書

看板C_and_CPP作者 (purpose)時間9年前 (2015/03/06 13:11), 編輯推噓1(108)
留言9則, 4人參與, 最新討論串2/3 (看更多)
※ 引述《mself (mself)》之銘言: : 開發平台(Platform): (Ex: VC++, GCC, Linux, ...) : Linux/Windows : 問題(Question): : 印象中,一些書說明物件導向的範例較不真實 : 極端一點,好像有看到舉例 : 鴨子呱呱叫、鴿子咕咕叫, : 鴨子和鴿子都是禽類,禽類會叫 : 禽類(鴨子).叫()是呱呱而不是咕咕 : ... 容小弟無知,岔一下題,因為說到動物的例子,突然很想貼一段話上來... 其實我個人一直認為,軟體界是愛嘴泡、愛筆戰的宅宅聚集地,每次看到某板又在開戰, 都覺得很不意外。而這其中的佼佼者,又肯定是寫 C/C++ 的最好鬥。 以下摘錄自:http://www.hellenico.gr/stl/drdobbs-interview.html If you start with a base class X at the root of your hierarchy and define a virtual equality operator on this class which takes an argument of the type X, then derive class Y from class X. What is the interface of the equality? It has equality which compares Y with X. Using animals as an example (OO people love animals), define mammal and derive giraffe from mammal. Then define a member function mate, where animal mates with animal and returns an animal. Then you derive giraffe from animal and, of course, it has a function mate where giraffe mates with animal and returns an animal. It's definitely not what you want. While mating may not be very important for C++ programmers, equality is. I do not know a single algorithm where equality of some kind is not used. You need templates to deal with such problems. You can have template class animal which has member function mate which takes animal and returns animal. When you instantiate giraffe, mate will do the right thing. The template is a more powerful mechanism in that respect. 以下摘錄自:http://www.hellenico.gr/stl/drdobbs-interview.html Q: Java is a new language, it is not a template to disable generic programming, everything must be a class. Java how you see? A: It took me a few months to write the program in Java. With its author predicted the contrary, it does not arouse my interest. I did not discover any new insights. Ever, my first time in a new language programming found no new insights. It retains all the things I never used in C++ - inheritance, virtual mechanism (OO garbage), and remove the useful things. It may be successful, after all, MS DOS success, but also for your readers to learn Java may be profitable, but it without any knowledge of the value. Look at their implementation of the hash table, look the the sort routine use of those "cool" the Sorting applet, and then try AWT. The best way to judge a language is to look at its advocates to write code. "! @ # $% ^ &% $! × ¥ #", (Annotation: the original "Radix enim omnium malorum est cupiditas), Java is obviously a money-oriented programming (MOP) example. SGI's Java foremost advocate told me to say: "Alex, you have to go where the money is." But I did not want to go where the money is, the kind of place, the taste is usually good to go. 以下這篇的傳聞,還需查證: https://www.reddit.com/r/cpp/comments/2vr7q6/this_article_seems_to_suggest_virtual_destructors/coke27u 縮短版網址:http://goo.gl/uwFyid I remember Stephanov once mentioned how in an interview they asked him why you would make your destructors virtual. Which he responded that he never makes his destructors virtual and his classes are used by lots of people. -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 124.8.133.212 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1425618676.A.480.html

03/06 13:28, , 1F
你到底多久沒更新了 comp.lang.c++(以及moderated)
03/06 13:28, 1F

03/06 13:29, , 2F
很早就已經不是戰場了 XD
03/06 13:29, 2F

03/06 13:29, , 3F
freenode也是整天看不到100句話 要吵都沒得吵了
03/06 13:29, 3F

03/06 13:30, , 4F
另外,OO people討厭死動物了,只有寫書的才愛...
03/06 13:30, 4F

03/06 14:34, , 5F
國外沒什麼在跑,是說 ptt 這邊的感覺
03/06 14:34, 5F

03/06 15:45, , 6F
OO people愛動物戳到我笑點XD!
03/06 15:45, 6F

03/06 17:11, , 7F
一樓不就是貓嗎 我愛死你了~~~~
03/06 17:11, 7F

03/06 17:53, , 8F
我也覺得那句很好笑,還有在繼承、virtual 後面加個
03/06 17:53, 8F

03/06 17:54, , 9F
括號 OO garbage 感覺嘴泡十足,他講話很有趣
03/06 17:54, 9F
文章代碼(AID): #1K-JRqI0 (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1K-JRqI0 (C_and_CPP)