JAVA外文资料翻译(共10页).doc

上传人:飞****2 文档编号:14073780 上传时间:2022-05-02 格式:DOC 页数:10 大小:57KB
返回 下载 相关 举报
JAVA外文资料翻译(共10页).doc_第1页
第1页 / 共10页
JAVA外文资料翻译(共10页).doc_第2页
第2页 / 共10页
点击查看更多>>
资源描述

《JAVA外文资料翻译(共10页).doc》由会员分享,可在线阅读,更多相关《JAVA外文资料翻译(共10页).doc(10页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、精选优质文档-倾情为你奉上外文文献原文及翻译作 者:辛明生物医学工程学院影像工程专业指导老师:杨谊生物医学工程学院信息技术系Parsing Java Abstraction of the Difference Between Classes and InterfacesIn Java language, abstract scale-up and with support class abstraction definition of two mechanisms. Because of these two kinds of mechanism of existence, just gives

2、 Java powerful object-oriented skills. Abstract scale-up and with between class abstraction definition for support has great similarities, even interchangeable, so many developers into line nonabstract class definition for abstract scale-up and it is becoming more casual with choice. In fact, both b

3、etween still has the very big difference, for their choice even reflected in problem domain essence of understanding, to design the intentions of the understand correctly and reasonable. This paper will for the difference analysis, trying to give a developer with a choice between them are based.Unde

4、rstand class abstractionAbstract class and interface in Java language is used for abstract classes (in this article nonabstract class not from abstract scale-up translation, it represents an abstract body, and abstract scale-up for Java language used to define class abstraction in one way, please re

5、aders distinguish) defined, then what are the abstract classes, use abstract classes for us any good?In object-oriented concept, we know all objects is through class to describe, but in turn not such. Not all classes are used to describe object, if a class does not contain enough information to port

6、ray a concrete object, this class is abstract classes. Abstract classes are often used to characterization of problem field in our analysis, design that the abstract concepts, is to the series will look different, but essentially the same exact conception of abstraction. For example: if we carry out

7、 a graphical editing software development, will find problem domain exists round, triangle so some specific concept, they are different, but they all belong to shape such a concept, shape this concept in problem domain is not exist, it is an abstract concept. Precisely because the abstract concepts

8、in problem field no corresponding specific concept, so to characterization abstract concepts nonabstract class cannot be instantiated.In an object-oriented field, mainly used for class abstraction types hidden. We can construct a fixed a group of behavior of abstract description, but this group of b

9、ehavior but can have any a possible concrete implementation. This abstract describe is abstract classes, and this an arbitrary a possible concrete realization is behaved for all possible derived class. Modules can be operating an abstract body. Due to the module dependent on a fixed abstraction body

10、, so it can are not allowed to modify, Meanwhile, through the abstract derived from the body, also can expand the behavior of this module function. Familiar with OCP readers must know, object-oriented design to be able to achieve a core principles OCP (Open - Closed flying), class abstraction is one

11、 of the key.From the perspectives of grammar definition abstract class and interfaceIn grammatical perspective, Java language for abstract scale-up and with gives different definitions below to define a way, called produce professional Demo abstract class as an example to illustrate the difference.U

12、se the abstract scale-up produce professional Demo abstract class defined as follows:abstract class Demoabstract void method1();abstract void method2();Use the way with produce professional Demo abstract class defined as follows:interface Demovoid method1();void method2();In the abstract scale-up ma

13、nner, produce professional Demo can have their own data members, also can have the members of the abstract method, and with the realization of the way, produce professional Demo can have only static cannot be modified data members (i.e. must is static, immigration, but in with generally doesnt defin

14、e data members), all the members of the methods is abstract. In a sense, with a special kind of abstract class.From programming, from the perspective of abstract scale-up and with can be used to achieve cancel thoughts make themselves. But in the specific use top still have some difference.First, ab

15、stract class in Java language suggests is a kind of inheriting relationship, a class can be used only once inheritance relationship (because Java do not support more inheritance ZhuanZhu). - However, a class but can implement multiple with. Maybe it is Java language designers in considering Java for

16、 multiple inheritance support of a compromise to consider it.Secondly, in the definition of abstract scale-up, we may give methods of default behavior. But in with the definition of method cannot have the default behaviour, to bypass this limits, must use entrust, but it will add some complexity, so

17、metimes can cause a lot of trouble.In class abstraction cannot define the default behaviour is there another serious problem that may cause on the maintenance of trouble. Because if later want to modify the interface (usually by such abstract scale-up or with to represent) to adapt to the new situat

18、ion (e.g., adding new methods or to have already used the method to add new parameters), will be very troublesome, might spend a lot of time (for a derived class many situation, especially). But if the interface is through scale-up abstract to realize, then may just need to modify defined in the abs

19、tract scale-up default behavior is ok.Similarly, if not in abstract class defined in the default behavior, can lead to the same method to appear in the abstract class every a derived class, violated a-one rule, principle, causing a-one place, the same code duplication against future maintenance. The

20、refore, in the abstract scale-up and with a choice between should be careful.From the design concept with abstract class and interfaceIt mainly from grammar definition and programming perspective, this paper discusses the area with abstract class and dont, these levels difference is relatively low l

21、evels of, the essence. This section will from another level: abstract class and with reflected design concept, analyse the difference. The author thinks that from this level analysis to understand the essence of both concept.As already mentioned, abstract class in Java language reveals a kind of inh

22、eriting relationship, want to make reasonable, the inheritance relationship between parent class and derived class must exist is - a relations, namely the superclass and derived class in concept in essence should be the same. For with criterion otherwise, it does not require with of implementers and

23、 with defined in concept is essentially a consistent, only is realized with defined a contract is just. In order to facilitate understanding, discussed below will through a simple illustrated with examples.Consider such a example, suppose in our problem field has a about filled the abstract concepts

24、, this filled with executive two movements open and close, then we can through scale-up or abstract with to define a said the abstract concept of type, define each pattern shown below:Use abstract class defined Door:abstract class Doorabstract void open();abstract void close();Use interface defined

25、Door:interface Doorvoid open();void close();Other concrete filled type can use extends the abstract class defined or filled with defined using implements the filled. Looks like using abstract class and with no much difference.If now requires more filled with alarm function. How can we design accordi

26、ng to the example of the class hierarchy? (in this case, it is mainly to show abstract class and with reflected in the design ideas, distinction, other aspect problem unrelated all did simplified or omitted)? Below will enumerate possible solutions, and from the design LiNianCeng face these differen

27、t scheme for analysis.Solution a:Simple in filled the definition of adding a alarm method, as follows:abstract class Doorabstract void open();abstract void close();abstract void alarm();orinterface Doorvoid open();void close();void alarm();So with alarm AlarmDoor defined as follows:class AlarmDoor e

28、xtends Doorvoid open()void close()void alarm()orclass AlarmDoor implements Doorvoid open()void close()void alarm()This method violated the object-oriented design of a core principles ISP (with flying Segregation), in the definition of filled the filled concept itself inherent behavior methods and an

29、other concept alarm behavior methods mix together. Such a problem is that those who cause depends only upon the concept of modules will be held because alarm this concept change (for example: modify the parameters) and alarm method, and vice still change.Solution b:Since open and close and alarm bel

30、ong to two different concepts, according to the ISP principle should consider them separately defined in representatives of these two concepts from the class abstraction. Definition means has: the two concepts are using abstract scale-up defined; Two concepts are used with defined; A concept using a

31、bstract scale-up defined, another concept using with defined.Obviously, due to Java language does not support multiple inheritance, so two concepts are using abstract class defined is not feasible. The latter two ways are feasible, but for their choice actually reflected in problem in the field of c

32、oncept natures 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

33、 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

34、 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 come to the design, realization to clear reflect what we mean by this? Front has said,

35、in Java language abstract scale-up said in an inheritance relationship, and inheriting relationship is in nature is a relationship. So for held this concept, we should use abstarct scale-up way to define. In addition, AlarmDoor has alarm functions, that it will be able to accomplish alarm concept de

36、finition of behavior, so alarm concept can be through with defined. Shown below:abstract class Doorabstract void open();abstract void close();interface Alarmvoid alarm();class Alarm Door extends Door implements Alarmvoid open()void close()void alarm()This realization basically can clearly reflect ou

37、r for problem domain, the correct understanding of our design intent reveals. Actually the abstract scale-up 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

38、: 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.Summary1. Abstract scale-up in Java language suggests is a kind of inheriting relationship, a class can be used only once inheritance relationship. Ho

39、wever, a class but can implement multiple with.2 in the abstract scale-up may have their own data members, also can have the members of the abstarct method, while in with, can have only static cannot be modified data members (i.e. must is static, immigration, but in with generally doesnt define data

40、 members), all the members of the methods is abstract.3. With abstract scale-up and reflected the design concept of different. Actually the abstract scale-up says is is - a relationship with said, was like - a relationship.4. Realize abstract classes and interface classes must realize, all of the me

41、thod. Abstract classes may have not abstract methods. Interface cannot have realization method.5. Interface definition of variable default is public, immigration, and static type to the initial value, so must realize class cannot be redefined, also cant change their values.6. Class abstraction of va

42、riable default is cut type, the value that can be in subclasses redefined, ok also and new assignment.7. Interface of the method are public default, abstract type.ConclusionAbstract class and with is Java language of two kinds of definition nonabstract class way, there are a great similarities. But

43、for their choice 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

44、of language of usage, like the reader friend can finely experience.详细解析Java中抽象类和接口的区别在Java语言中,abstract class和interface 是支持抽象类定义的两种机制。正是由于这两种机制的存在,才赋予了Java强大的 面向对象能力。abstract class和interface之间在对于抽象类定义的支持方面具有很大的相似性,甚至可以相互替换,因此很多开发者在进 行抽象类定义时对于abstract class和interface的选择显得比较随意。其实,两者之间还是有很大的区别的,对于它们的选择甚

45、至反映出对于问题领域本质的理解、对于设计意图的理解是否正确、合理。本文将对它们之间的区别进行一番剖析,试图给开发者提供一个在二者之间进行选择的依据。理解抽象类abstract class和interface在Java语言中都是用来进行抽象类(本文中的抽象类并非从abstract class翻译而来,它表示的是一个抽象体,而abstract class为Java语言中用于定义抽象类的一种方法,请读者注意区分)定义的,那么什么是抽象类,使用抽象类能为我们带来什么好处呢?在面向对象的概念中,我们知道所有的对象都是通过类来描绘的,但是反过来却不是这样。并不是所有的类都是用来描绘对象的,如果一个类中没有

46、包含足够的信息来描绘一个具体的对象,这样的类就是抽象类。抽象类往往用来表征我们在对问题领域进行分析、设计中得出的抽象概念,是对一系列看上去不同,但是本质上相同的具体概念的抽象。比如:如果我们进行一个图形编辑软件的开发,就会发现问题领域存在着圆、三角形这样一些具体概念,它们是不同的,但是它们又都属于形状这样一个概念,形状这个概念在问题领域是不存在的,它就是一个抽象概念。正是因为抽象的概念在问题领域没有对应的具体概念,所以用以表征抽象概念的抽象类是不能够实例化的。在面向对象领域,抽象类主要用来进行类型隐藏。我们可以构造出一个固定的一组行为的抽象描述,但是这组行为却能够有任意个可能的具体实现方式。这

47、个抽象描述就是抽象类,而这一组任意个可能的具体实现则表现为所有可能的派生类。模块可以操作一个抽象体。由于模块依赖于一个固定的抽象体,因此它可以是不允许修改的;同时,通过从这个抽象体派生,也可扩展此模块的行为功能。熟悉OCP的读者一定知道,为了能够实现面向对象设计的一个最核心的原则OCP(Open-Closed Principle),抽象类是其中的关键所在。从语法定义层面看abstract class 和 interface在语法层面,Java语言对于abstract class和interface给出了不同的定义方式,下面以定义一个名为Demo的抽象类为例来说明这种不同。使用abstract

48、class的方式定义Demo抽象类的方式如下:abstract class Demoabstract void method1();abstract void method2();使用interface的方式定义Demo抽象类的方式如下:interface Demovoid method1();void method2();在abstract class方式中,Demo可以有自己的数据成员,也可以有非 abstract的成员方法,而在interface方式的实现中,Demo只能够有静态的不能被修改的数据成员(也就是必须是static final的,不过在interface中一般不定义数据成员),所有的成员方法都是abstract的。从某种意义上说,interface是一种特殊形式的abstract class。从编程的角度来看,abstract class和interface都可以用来实现 design by contract 的思想。但是在具体的使用上面还是有一些区别的。首先,abstract class 在 Java 语言中表示的是一种继承关系,一个类只能使用一次继承关系(因为Java不支持多继承 - 转注)。但是,一个类却可以实现多个interface。也许,这是Java语言的设计者在考虑Java对于多重继承的

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com