分享
分销 收藏 举报 申诉 / 12
播放页_导航下方通栏广告

类型毕设外文翻译-详细解析Java中抽象类和接口的区别.doc

  • 上传人:天****
  • 文档编号:10696958
  • 上传时间:2025-06-10
  • 格式:DOC
  • 页数:12
  • 大小:57.01KB
  • 下载积分:8 金币
  • 播放页_非在线预览资源立即下载上方广告
    配套讲稿:

    如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。

    特殊限制:

    部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。

    关 键  词:
    外文 翻译 详细 解析 Java 抽象 接口 区别
    资源描述:
    Parsing Java Abstraction of the Difference Between Classes and Interfaces In 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 Java powerful object-oriented skills. Abstract scale-up and with between classes abstraction definition for support has great similarities, even interchangeable, so many developers into line non-abstract class definition for abstract scale-up and it is becoming more casual with choice. In fact, both between still has the very big difference, for their choice even reflected in problem domain essence of understanding, to design the intentions of the understanding correctly and reasonable. This paper will for the difference analysis, trying to give a developer with a choice between them are based. Understand class abstraction Abstract class and interface in Java language is used for abstract classes (in this article non-abstract 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 readers 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 portray 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 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 in problem field no corresponding specific concept, so to characterization abstract concepts non-abstract 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 behavior 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, 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 principle OCP (Open - Closed flying), class abstraction is one of the key. From the perspectives of grammar definition abstract class and interface In 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. In the abstract scale-up manner, 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, 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, abstract 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 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 behavior, to bypass this limits, must use entrust, but it will add some complexity, sometimes can cause a lot of trouble. In class abstraction cannot define the default behavior 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 situation (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 abstract 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. Therefore, in the abstract scale-up and with a choice between should be careful. From the design concept with abstract class and interface It mainly from grammar definition and programming perspective, this paper discusses the area with abstract class and don't, these levels difference is relatively low levels of, the essence. This section will from another level: abstract class and with reflected design concept, analyst the difference. The author thinks that from this level analysis to understand the essence of both concepts. As already mentioned, abstract class in Java language reveals a kind of inheriting relationship, want to make reasonable, the inheritance relationship between parent class and derived class must exist "is - a" relations, namely the super class and derived class in concept in essence should be the same. For with criterion otherwise, it does not require with of implementers and with defined in concept is essentially a consistent, only is realized with defined a contract is just. In order to facilitate understandings. Consider such a example, suppose in our problem field has a about filled the abstract concepts, 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 . Other concrete filled type can use extends the abstract class defined or filled with defined using implements the filled. Look like using abstract class and with no much difference. If now requires more filled with alarm function. How can we design according 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 different schemes for analysis. 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 another 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. Since open and close and alarm belong 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 abstract 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 concept nature'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 come to the design, realization to clear reflect what we mean by this? Front has said, 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 abstract scale-up way to define. In addition, AlarmDoor has alarm functions, that it will be able to accomplish 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 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: 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 scale-up in Java language suggests is a kind of inheriting relationship, a class can be used only once inheritance relationship. However, 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 abstract method, while in with, can have only static cannot be modified data members (i.e. must is static, immigration, but in with generally doesn't define data 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 method. 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 can't change their values. 6. Class abstraction of variable 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. Conclusion Abstract class and with is Java language of two kinds of definition non-abstract class way, there are a great similarities. But 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 of language of usage, like the reader friend can finely experience. 详细解析Java中抽象类和接口的区别 在Java语言中,abstract class和interface 是支持抽象类定义的两种机制。正是由于这两种机制的存在,才赋予了Java强大的面向对象能力。abstract class和interface之间在对于抽象类定义的支持方面具有很大的相似性,甚至可以相互替换,因此很多开发者在进 行抽象类定义时对于abstract class和interface的选择显得比较随意。其实,两者之间还是有很大的区别的,对于它们的选择甚至反映出对于问题领域本质的理解、对于设计意图的理解是否正确、合理。本文将对它们之间的区别进行一番剖析,试图给开发者提供一个在二者之间进行选择的依据。 理解抽象类 abstract class和interface在Java语言中都是用来进行抽象类(本文中的抽象类并非从abstract class翻译而来,它表示的是一个抽象体,而abstract class为Java语言中用于定义抽象类的一种方法,请读者注意区分)定义的,那么什么是抽象类,使用抽象类能为我们带来什么好处呢? 在面向对象的概念中,我们知道所有的对象都是通过类来描绘的,但是反过来却不是这样。并不是所有的类都是用来描绘对象的,如果一个类中没有包含足够的信息来描绘一个具体的对象,这样的类就是抽象类。抽象类往往用来表征我们在对问题领域进行分析、设计中得出的抽象概念,是对一系列看上去不同,但是本质上相同的具体概念的抽象。比如:如果我们进行一个图形编辑软件的开发,就会发现问题领域存在着圆、三角形这样一些具体概念,它们是不同的,但是它们又都属于形状这样一个概念,形状这个概念在问题领域是不存在的,它就是一个抽象概念。正是因为抽象的概念在问题领域没有对应的具体概念,所以用以表征抽象概念的抽象类是不能够实例化的。 在面向对象领域,抽象类主要用来进行类型隐藏。我们可以构造出一个固定的一组行为的抽象描述,但是这组行为却能够有任意个可能的具体实现方式。这个抽象描述就是抽象类,而这一组任意个可能的具体实现则表现为所有可能的派生类。模块可以操作一个抽象体。由于模块依赖于一个固定的抽象体,因此它可以是不允许修改的;同时,通过从这个抽象体派生,也可扩展此模块的行为功能。熟悉OCP的读者一定知道,为了能够实现面向对象设计的一个最核心的原则OCP(Open-Closed Principle),抽象类是其中的关键所在。 从语法定义层面看abstract class 和 interface 在语法层面,Java语言对于abstract class和interface给出了不同的定义方式,下面以定义一个名为Demo的抽象类为例来说明这种不同。 在abstract class方式中,Demo可以有自己的数据成员,也可以有非 abstract的成员方法,而在interface方式的实现中,Demo只能够有静态的不能被修改的数据成员,所有的成员方法都是abstract的。从某种意义上说,interface是一种特殊形式的abstract class。 从编程的角度来看,abstract class和interface都可以用来实现 "design by contract" 的思想。但是在具体的使用上面还是有一些区别的。 首先,abstract class 在 Java 语言中表示的是一种继承关系,一个类只能使用一次继承关系(因为Java不支持多继承 -- 转注)。但是,一个类却可以实现多个interface。也许,这是Java语言的设计者在考虑Java对于多重继承的支持方面的一种折中考虑吧。 其次,在abstract class的定义中,我们可以赋予方法的默认行为。但是在interface的定义中,方法却不能拥有默认行为,为了绕过这个限制,必须使用委托,但是这会增加一些复杂性,有时会造成很大的麻烦。 在抽象类中不能定义默认行为还存在另一个比较严重的问题,那就是可能会造成维护上的麻烦。因为如果后来想修改类的界面(一般通过abstract class或interface来表示)以适应新的情况(比如,添加新的方法或者给已用的方法中添加新的参数)时,就会非常的麻烦,可能要花费很多的时间(对于派生类很多的情况,尤为如此)。但是如果界面是通过abstract class来实现的,那么可能就只需要修改定义在abstract class中的默认行为就可以了。 同样,如果不能在抽象类中定义默认行为,就会导致同样的方法实现出现在该抽象类的每一个派生类中,违反了 "one rule,one place" 原则,造成代码重复,同样不利于以后的维护。因此,在abstract class和interface间进行选择时要非常的小心。 从设计理念层面看abstract class和interface 上面主要从语法定义和编程的角度论述了abstract class和interface的区 别,这些层面的区别是比较低层次的、非本质的。本小节将从另一个层面:abstract class和interface所反映出的设计理念,来分析一下二者的区别。作者认为,从这个层面进行分析才能理解二者概念的本质所在。 前面已经提到过,abstract class在Java语言中体现了一种继承关系,要想使得继承关系合理,父类和派生类之间必须存在"is-a"关系,即父类和派生类在概念本质上应该是相同的。对于interface来说则不然,并不要求interface的实现者和interface定义在概念本质上是一致的,仅仅是实现了interface定义的契约而已。为了使论述便于理解,下面将通过一个简单的实例进行说明。 考虑这样一个例子,假设在我们的问题领域中有一个关于Door的抽象概念,该Door具有执行两个动作open和close,此时我们可以通过abstract class或者interface来定义一个表示该抽象概念的类型。 其他具体的Door类型可以extends使用abstract class方式定义的Door或者implements使用interface方式定义的Door。看起来好像使用abstract class和interface没有大的区别。 如果现在要求Door还要具有报警的功能。我们该如何设计针对该例子的类结构呢(在本例中,主要是为了展示abstract class和interface反映在设计理念上的区别,其他方面无关的问题都做了简化或者忽略)?下面将罗列出可能的解决方案,并从设计理念层面对这些不同的方案进行分析。 这种方法违反了面向对象设计中的一个核心原则ISP(Interface Segregation Principle),在Door的定义中把Door概念本身固有的行为方法和另外一个概念"报警器"的行为方法混在了一起。这样引起的一个问题是那些仅仅依赖于Door这个概念的模块会因为"报警器"这个概念的改变(比如:修改alarm方法的参数)而改变,反之依然。 既然open、close和alarm属于两个不同的概念,根据ISP原则应该把它们分别定义在代表这两个概念的抽象类中。定义方式有:这两个概念都使用abstract class方式定义;两个概念都使用interface方式定义;一个概念使用abstract class方式定义,另一个概念使用interface方式定义。 显然,由于Java语言不支持多重继承,所以两个概念都使用abstract class方式定义是不可行的。后面两种方式都是可行的,但是对于它们的选择却反映出对于问题领域
    展开阅读全文
    提示  咨信网温馨提示:
    1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
    2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
    3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
    4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
    5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
    6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

    开通VIP折扣优惠下载文档

    自信AI创作助手
    关于本文
    本文标题:毕设外文翻译-详细解析Java中抽象类和接口的区别.doc
    链接地址:https://www.zixin.com.cn/doc/10696958.html
    页脚通栏广告

    Copyright ©2010-2025   All Rights Reserved  宁波自信网络信息技术有限公司 版权所有   |  客服电话:0574-28810668    微信客服:咨信网客服    投诉电话:18658249818   

    违法和不良信息举报邮箱:help@zixin.com.cn    文档合作和网站合作邮箱:fuwu@zixin.com.cn    意见反馈和侵权处理邮箱:1219186828@qq.com   | 证照中心

    12321jubao.png12321网络举报中心 电话:010-12321  jubao.png中国互联网举报中心 电话:12377   gongan.png浙公网安备33021202000488号  icp.png浙ICP备2021020529号-1 浙B2-20240490   


    关注我们 :微信公众号  抖音  微博  LOFTER               

    自信网络  |  ZixinNetwork