JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java SE 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Java 違反物件導向?? [精華]
Eva

甜膩的酒窩



發文: 101
積分: 1
於 2003-08-20 20:04 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
這幾天到處面試
被問到一個我回答不出來的問題

題目是: Java有哪些地方是違反物件導向的精神?

還請大大們指導一下 SadSad


reply to postreply to post
作者 Re:Java 違反物件導向?? [Re:Eva]
iampoya

Speculator

版主

發文: 169
積分: 8
於 2003-08-20 20:10 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Reflect !!

reply to postreply to post
Japan Adult Video Album
作者 Re:Java 違反物件導向?? [Re:iampoya]
Duncan

還隱隱作痛

版主

發文: 7816
積分: 39
於 2003-08-20 21:36 user profilesend a private message to usersend email to Duncanreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
iampoya wrote:
Reflect !!


reflection 哪裡有違反?
如果看的到內餡就算的違反,那麼公開的 VM spec 才是禍首。


reply to postreply to post

給我
辣味豆腐 其餘免談
作者 Re:Java 違反物件導向?? [Re:Duncan]
iampoya

Speculator

版主

發文: 169
積分: 8
於 2003-08-20 21:43 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
呣∼像RTTI醬子
以名尋物的思維…我覺得一點也不OO呀


reply to postreply to post
Japan Adult Video Album
作者 Re:Java 違反物件導向?? [Re:Duncan]
linexpmail

好玩就好



發文: 456
積分: 15
於 2003-08-20 21:45 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
物件導向解釋權在誰手上?誰說了算?
http://www.jvoegele.com/software/langcomp.html

我會投 java 沒辦法送訊息 send message 給 int 這類特殊 type 一票 。


reply to postreply to post
不除妄想不求真
作者 Re:Java 違反物件導向?? [Re:Eva]
Eva

甜膩的酒窩



發文: 101
積分: 1
於 2003-08-20 22:12 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
剛剛某站長竟然嫌我的問題太無聊
我就是不懂才問的啊.....Cry

謝謝各位帥到不行的大大 My heart


reply to postreply to post
作者 Re:Java 違反物件導向?? [Re:linexpmail]
Duncan

還隱隱作痛

版主

發文: 7816
積分: 39
於 2003-08-20 22:40 user profilesend a private message to usersend email to Duncanreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
linexpmail wrote:
物件導向解釋權在誰手上?誰說了算?
http://www.jvoegele.com/software/langcomp.html

我會投 java 沒辦法送訊息 send message 給 int 這類特殊 type 一票 。


我到那網頁看了一下,很驚訝!Python 竟然不是 pure OOP?!
我完全想不出這網頁的作者是從那一點來看。


reply to postreply to post

給我
辣味豆腐 其餘免談
作者 Re:Java 違反物件導向?? [Re:Eva]
caterpillar

良葛格

版主

發文: 2613
積分: 70
於 2003-08-20 22:46 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Eva wrote:
剛剛某站長竟然嫌我的問題太無聊
我就是不懂才問的啊.....Cry

謝謝各位帥到不行的大大 My heart


應該是問這個問題的主管太無聊吧!。。。。。

什麼違反不違反的,這種集中在語言上的觀念議題一直是我覺得最無聊的問題。

早有先進提過,會用OO的,即使是C甚至VB,也可以使用的很OO,不會用的,給它一個很OO的語言,也是寫的很XX。

其實有幾個人真正瞭解OO?很不幸的,我是其中之一,OO的真義仍在鑽研體會中啊。。。。。SadSadSad


caterpillar edited on 2003-08-20 22:49
reply to postreply to post
良葛格學習筆記
作者 Re:Java 違反物件導向?? [Re:Eva]
harrisonlin



發文: 0
積分: 0
於 2003-08-22 07:46 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Java 違反OOP的部份 - static field & method。

Python本來就不是純OOP 語言!!即使不懂OOP,你還是可以使用Python,否則連一個簡單的script都要搞OO,豈不累人??

"Python supports object-oriented programming with classes and multiple inheritance."

Python"支援"OOP,但不是純OOP語言。


harrisonlin edited on 2003-08-22 07:51
reply to postreply to post
作者 Re:Java 違反物件導向?? [Re:harrisonlin]
harrisonlin



發文: 0
積分: 0
於 2003-08-22 07:49 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
用C & VB可以實踐inheritance, polymorphism....真的嗎?

可不可以分享一下?^^


reply to postreply to post
作者 Re:Java 違反物件導向?? [Re:harrisonlin]
ianhong





發文: 2
積分: 0
於 2003-08-22 09:58 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Post is deleted

ianhong edited on 2007-04-26 15:07
reply to postreply to post
作者 Re:Java 違反物件導向?? [Re:ianhong]
harrisonlin



發文: 0
積分: 0
於 2003-08-22 10:13 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
ianhong wrote:
struct aa{
data aa;
};

struct bb {
aa oldaa;
data extrabb;
};


你確定這是繼承?還是複合?

OO的還有一項特性,也請你一併用C展示一下吧!!


reply to postreply to post
作者 Re:Java 違反物件導向?? [Re:Eva]
ray_linn

什么都不懂的小白

版主

發文: 540
積分: 10
於 2003-08-22 10:18 user profilesend a private message to usersend email to ray_linnreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
JDBC算不算? 基本就是一個順序化的過程....

reply to postreply to post
飞翔的候鸟
作者 Re:Java 違反物件導向?? [Re:harrisonlin]
ianhong





發文: 2
積分: 0
於 2003-08-22 10:32 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Post is deleted

ianhong edited on 2007-04-26 15:08
reply to postreply to post
作者 Re:Java 違反物件導向?? [Re:ianhong]
harrisonlin



發文: 0
積分: 0
於 2003-08-22 10:42 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
ianhong wrote:
我想重點在於達到目的, 不是過程.


好吧...我只能說:你真行...Smile


reply to postreply to post
作者 Re:Java 違反物件導向?? [Re:Duncan]
popcorny

Jakarta 2%

版主

發文: 752
積分: 20
於 2003-08-22 11:16 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Duncan wrote:
我到那網頁看了一下,很驚訝!Python 竟然不是 pure OOP?!
我完全想不出這網頁的作者是從那一點來看。

裡面的一段文字

Python is often heralded as an Object-Oriented language, but its support for Object-Orientation seems to have been tacked on. Some operations are implemented as methods, while others are implemented as global functions. Also, the need for an explicit "self" parameter for methods is awkward. Some complain about Python's lack of "private" or "hidden" attributes, which goes against the Encapsulation/Information Hiding principle, while others feel that Python's "privateness is by convention" approach offers all of the practical benefits as language-enforced encapsulation without the hassle.


reply to postreply to post
作者 Re:Java 違反物件導向?? [Re:harrisonlin]
Duncan

還隱隱作痛

版主

發文: 7816
積分: 39
於 2003-08-22 12:40 user profilesend a private message to usersend email to Duncanreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
harrisonlin wrote:
Java 違反OOP的部份 - static field & method。

Python本來就不是純OOP 語言!!即使不懂OOP,你還是可以使用Python,否則連一個簡單的script都要搞OO,豈不累人??

"Python supports object-oriented programming with classes and multiple inheritance."

Python"支援"OOP,但不是純OOP語言。


能請你說明一下,你心中關於Python本來就不是純OOP 語言的看法嗎?

以 Python 有 function 來指明 Python 不符 OOP,就顯得太淺了。真要說 Python 沒有資訊隱藏的功能,我個人則是覺得封裝指的是資料的聚合即是,否則你用 C 也不做出資訊隱藏的封裝。


reply to postreply to post

給我
辣味豆腐 其餘免談
作者 Re:Java 違反物件導向?? [Re:Duncan]
harrisonlin



發文: 0
積分: 0
於 2003-08-22 14:49 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Duncan wrote:
能請你說明一下,你心中關於Python本來就不是純OOP 語言的看法嗎?

以 Python 有 function 來指明 Python 不符 OOP,就顯得太淺了。真要說 Python 沒有資訊隱藏的功能,我個人則是覺得封裝指的是資料的聚合即是,否則你用 C 也不做出資訊隱藏的封裝。


我所說"Python"不是純OO語言,是指可以使用Python來完成工作的手法,不必一定是OO的,也可以把它當作程序導向的語言來使用!猶如C++也是hybrid一樣,不是嗎?


harrisonlin edited on 2003-08-22 15:04
reply to postreply to post
作者 Re:Java 違反物件導向?? [Re:harrisonlin]
Duncan

還隱隱作痛

版主

發文: 7816
積分: 39
於 2003-08-22 19:56 user profilesend a private message to usersend email to Duncanreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
harrisonlin wrote:
我所說"Python"不是純OO語言,是指可以使用Python來完成工作的手法,不必一定是OO的,也可以把它當作程序導向的語言來使用!猶如C++也是hybrid一樣,不是嗎?


C/C++ 你可以寫個 main method 就完成程式的全部,不用到任何物件的觀念。但是你用 Python 寫幾行你認為的 script 作點小事情,其實已經有 OO 的味道在裡頭。

1
2
3
4
5
6
7
8
# writen in Python language
>>> dir(5)
['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delattr__', '__div__', '__divmod__', '__doc__', 
'__float__', '__floordiv__', '__getattribute__', '__hash__', '__hex__', '__init__', '__int__', '__invert__', '__long__', 
'__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', '__oct__', '__or__', '__pos__', 
'__pow__', '__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__repr__', '__rfloordiv__', '__rlshift__', 
'__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', 
'__setattr__', '__str__', '__sub__', '__truediv__', '__xor__']

Python 沒有 primitive types 只有內建的 type(numeric: integer, long, float, complex; sequence: string, tuple, list; Mapping: Dictionary; etc..)。即使是 numeric literal 代表的也是有數值意義的物件,由 dir(5) 可看出 5 所支援的操作。

1
2
3
4
5
6
>>> a=87
>>> b=87
>>> a==b
1
>>> a is b
1

前一段說過像 5 這樣的數值本質上是個物件,a=87; b=87 並不是把 87 這個 value copy 給 a, b 兩變數,而是把一個 integer object 其值為 87 的物件之 reference assign 給 a, b 變數,所以用 "is" operator 來測試兩個變數所參考的物件是否為同一個(operator == 才是比較兩者的值),結果是同一個。

1
2
3
4
5
6
7
8
9
>>> def SayHello():
  print 'Hello, guys!'
 
  
>>> Hi=SayHello
>>> SayHello()
Hello, guys!
>>> Hi()
Hello, guys!

用 def 去定義一個函式,在 Python 裡這不是一個 declaration,而是一個有執行動作的 statement,定義(組裝)了一個 function/callable object,行為是:
1
print 'Hello, guys!'

"並" assign 這個 function/callable object reference 給 SayHello 變數,可以將這個 object reference 再 copy 給另一變數 Hi,之後可以透過 Hi 變數來執行這個 function/callable。

你說上面這些加起來只不過是一些零散的碼而已?
當你在 Python console 寫這些碼時,其實是在一個叫做 __main__ 的 module 裡(module 也是一種型態的物件。另外,當你寫的 Python module 透過 Python interpreter 直接來執行而不是作匯入的動作時,module 的內容就變成 __main__ module 的一部份),可說是 module 的一部份,只是 Python 幾乎沒有純宣告/定義的 statement(除了 global keyword 的用法外),每個 statement 都有執行動作(在定義類別時也不例外),所以看起來好像在寫 code,但也可以視為 member definition。

這裡是 Java 版,不方便提太多 Python 的東西。我只是要表達,同樣的碼拿到 C++ 語言 main function 裡,可以說是很沒有 OO 的概念,但是放在 Python 裡,我覺得很有 OO 的味道,這就是 C++, Python 本質上的差異。你可以說 Python 為一 hybrid PL,但以我個人的使用經驗,我覺得 Python 算是蠻純的 OOP,不論是比起 C++ 亦或是 Java。


Duncan edited on 2003-08-22 19:59
reply to postreply to post

給我
辣味豆腐 其餘免談
作者 Re:Java 違反物件導向?? [Re:Duncan]
harrisonlin



發文: 0
積分: 0
於 2003-08-22 22:44 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Duncan 兄,我想我們對pure OOPL的定義不盡相同。

您認為"是否為Pure OOPL"要從這個PL的底層運作機制看起,而我卻認為要從"允許user的使用手法"來看。

就好像 script language 的定義一樣, 只要 user 認為他在寫一個 script, 那麼它就是一個 script language。 User 不用理會 Python 的底層動用了什麼機制,還是可以用 procedural based 的方式去完成他的工作。

所以我認為 Python 不是 pure OOPL,而是支援 OOP 的原因在此,和那個表格的作者一樣,都是個人觀點。

(在JAVA版給人家哈啦起 Python...真是不好意思....)


reply to postreply to post
作者 Re:Java 違反物件導向?? [Re:Eva]
dasein





發文: 2
積分: 0
於 2003-08-27 00:19 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
不能多重繼承算不算?

reply to postreply to post
NOT just jaVa
作者 Re:Java 違反物件導向?? [Re:Eva]
eat_meat





發文: 10
積分: 0
於 2003-08-31 01:02 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
若老闆問我 , 我可能也回答不出來
有時候我寫的程式會違反OO的精神

http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html

Sleepy


reply to postreply to post
作者 Re:Java 違反物件導向?? [Re:harrisonlin]
T55555

Java, Ruby, Haskell

版主

發文: 1026
積分: 24
於 2003-09-05 05:25 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
harrisonlin wrote:
Python本來就不是純OOP 語言!!即使不懂OOP,你還是可以使用Python,否則連一個簡單的script都要搞OO,豈不累人??


Not at all, even simple Script can be OO.

Check the pure OO Script language: Ruby (www.ruby-lang.org)
( even number 1 is an Object, anything are Object in Ruby like Smalltalk )

And the compare of Python and Ruby:

http://www.rubygarden.org/iowa/faqtotum/ab2VO6Xo2jYM2/b/1.11.7.2.5


browser edited on 2003-09-05 08:31
reply to postreply to post
作者 Re:Java 違反物件導向?? [Re:T55555]
800





發文: 2
積分: 0
於 2006-04-15 00:53 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
premitive data type 確實是 Java 很不 O-O 的地方
不過沒辦法,若想把使用者從 C/C++ 那國拉過來,提供 premitive data type 是個很重要的手段,但是這也使得 Java 要同時處理 object 與 premitive data type 時變得很讓人幹譙。


reply to postreply to post
作者 Re:Java 違反物件導向?? [Re:harrisonlin]
momotalo





發文: 8
積分: 0
於 2006-04-17 12:04 user profilesend a private message to usersend email to momotaloreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
harrisonlin wrote:
你確定這是繼承?還是複合?

OO的還有一項特性,也請你一併用C展示一下吧!!


把物件當成結構來看~~嗯
我就是這樣開始學OO的
英雄所見略同!!


reply to postreply to post
總在一番刺骨奇寒之後,見那光彩奪目的不凡
go to first page go to previous page  1   2  go to next page go to last page
» JWorld@TW »  Java SE 討論區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8