没有合适的资源?快使用搜索试试~ 我知道了~
Java中抽象类和接口的区别
5星 · 超过95%的资源 需积分: 50 3 下载量 104 浏览量
2018-05-03
13:34:36
上传
评论
收藏 62KB DOC 举报
温馨提示
在Java语言中,abstract class和interface 是支持抽象类定义的两种机制。正是由于这两种机制的存在,才赋予了Java强大的面向对象能力。abstract class和interface之间在对于抽象类定义的支持方面具有很大的相似性,甚至可以相互替换,因此很多开发者在进 行抽象类定义时对于abstract class和interface的选择显得比较随意。其实,两者之间还是有很大的区别的,对于它们的选择甚至反映出对于问题领域本质的理解、对于设计意图的理解是否正确、合理。本文将对它们之间的区别进行一番剖析,试图给开发者提供一个在二者之间进行选择的依据
资源推荐
资源详情
资源评论
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
剩余12页未读,继续阅读
qq_42125539
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页