【正文】
oice but again often reflects on issues in the field of generalized read essence of understanding, to reflect the design intent is correct and reasonable, whether because they show the concept between different relation (although can realize the function demand). This is actually a kind of language of usage, like the reader friend can finely experience. 詳細(xì)解析 Java 中抽象類(lèi)和接口的區(qū)別 在 Java 語(yǔ)言中, abstract class 和 interface 是支持抽象類(lèi)定義的兩種機(jī)制。比如:如果我們進(jìn)行一個(gè)圖形編輯軟件的開(kāi)發(fā),就會(huì)發(fā)現(xiàn)問(wèn)題領(lǐng)域存在著圓、三角形這樣一些具體概念,它們是不同的,但是它們又都屬于形狀這樣一個(gè)概念,形狀這個(gè)概念在問(wèn)題領(lǐng)域是不存在的,它就是一個(gè)抽象概念。 從語(yǔ)法定義層面看 abstract class 和 interface 在語(yǔ)法層面, Java 語(yǔ)言對(duì)于 abstract class 和 interface 給出了不同的定義方式,下面以定義一個(gè)名為 Demo 的抽象類(lèi)為例來(lái)說(shuō)明這種不同。 其次,在 abstract class 的定義中,我們可以賦予方法的默認(rèn)行為。 本小節(jié)將從另一個(gè)層面: abstract class 和interface 所反映出的設(shè)計(jì)理念,來(lái)分析一下二者的區(qū)別。 如果現(xiàn)在要求 Door 還要具有報(bào)警的功能。我們一一來(lái)分析、說(shuō)明。 小結(jié) 1. abstract class 在 Java 語(yǔ)言中表示的是一種繼承關(guān)系,一個(gè)類(lèi)只能使用一次繼承關(guān)系。 5. 接口中定義的變量默認(rèn)是 public static final 型,且必須給其初值,所以實(shí)現(xiàn)類(lèi)中不能重新定義,也不能改變其值。 指導(dǎo)教師評(píng)語(yǔ) 該生外文翻譯的內(nèi)容與課題研究方向所涉及的技術(shù),基本一致,翻譯的基本準(zhǔn)確,字?jǐn)?shù)達(dá)到開(kāi)題中對(duì)外文文獻(xiàn)的要求,格式比較規(guī)范。抽象類(lèi)中可以有非抽象方法。 這種實(shí)現(xiàn)方式基本上能夠明確的反映出我們對(duì)于問(wèn)題領(lǐng)域的理解,正確的揭示我們的設(shè)計(jì)意圖。 顯然,由于 Java 語(yǔ)言不支持多重繼承,所以兩個(gè)概念都使 用 abstract class 方式定義是不可行的。 其他具體 的 Door 類(lèi)型可以 extends 使用 abstract class 方式定義的 Door 或者implements 使用 interface 方式定義的 Door。因此,在 abstract class 和 interface 間進(jìn)行選擇時(shí)要非常的小心。但是,一個(gè)類(lèi)卻可以實(shí)現(xiàn)多個(gè)interface。由于模塊依賴于一個(gè)固定的抽象體,因此它可以是不允許修改的;同時(shí),通過(guò)從這個(gè)抽象體派生,也可擴(kuò)展此模塊的行為功能。并不是所有的類(lèi)都是用來(lái)描繪對(duì)象的,如果一個(gè)類(lèi)中沒(méi)有包含足夠的信息來(lái)描繪一個(gè)具體的對(duì)象,這樣的類(lèi)就是抽象類(lèi)。s understanding, whether for design intent reflect the correct and reasonable. We are a result analysis and description. If the two concepts are used with ways to define, then reflects two problems: 1, we may not understand clearly problem domain, AlarmDoor in concept essentially exactly is held or alarm? 2, if we in problem field understanding no problems, for example: we through for problem domain analysis found that AlarmDoor in concept in essence and filled is consistent, then we realize when he failed to correct reveal our design intention, because in these two concepts on the definitions (both use with defined) reflect reflected these meanings. If we in problem field understanding is: AlarmDoor in concept is essentially, at the same time it is filled with alarm function. How should we e to the design, realization to clear reflect what we mean by this? Front has said, in Java language abstract scaleup said in an inheritance relationship, and inheriting relationship is in nature is a relationship. So for held this concept, we should use abstract scaleup way to define. In addition, AlarmDoor has alarm functions, that it will be able to acplish alarm concept definition of behavior, so alarm concept can be through with defined. This realization basically can clearly reflect our for problem domain, the correct understanding of our design intent reveals. Actually the abstract scaleup says is is a relationship with said, was like a relationship, everyone when the choice can be used as a basis, which, of course, is based on understanding the problem domain, for instance: if we think AlarmDoor in concept is essentially alarm, have again at the same time, then held the function of the above definition way will in turn. Summary 1. Abstract scaleup in Java language suggests is a kind of inheriting relationship, a class can be