为什么我们使用抽象句? [英] why we use abstract clases?

查看:77
本文介绍了为什么我们使用抽象句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果无法创建抽象类的实例,为什么要使用抽象类.创建抽象类的目的是什么?

why we use abstract classes if we can not create its instants.what is the purpose of creating abstract classes

推荐答案

阅读本文:

面向对象的编程概念(OOP)以及更多内容 [ ^ ]

希望对您有所帮助:)
Read this:

Introduction to Object Oriented Programming Concepts (OOP) and More[^]

hope it helps :)


根据语言的实现,将对此问题有多个答案.但是,虽然您不能创建虚拟抽象类的特定实例,但是您将能够创建从该抽象类继承的类的实例.现在,您的实例封装了抽象类,并且所有公共和受保护的方法都可以使用.正是这种封装提供了软件重用,并将增强类库的使用.

尝试向Google获取有关类库设计的更多信息. :)
Depending upon the language implementation, there will be several answers to this question. However, while you can not create a specific instance of a virtual abstract class, you will be able to creat an instance of a class that inherits from that abstract class. Your instance now encapsulates the abstract class and all public and protected methods are available to use. It is this encapsulation that provides for software reuse and will enhance the class library''s use.

Try to Google for more information on class library design. :)


对于这种问题,Google将是一个更好的解决方案.

了解以下内容:何时使用抽象类和接口 [
For this kind of question Google would be a far better solution.

Why we uses abstract classes[^]

Learn This: When to use an Abstract Class and an Interface[^]

By the way, any good book on object-oriented programming should help you understand the purpose and use of abstract classes.

Generally, one would prefer interfaces to abstract classes as they are more separated from the implementation in the sense that it is much easier to reuse an interface for different classes that to reuse an abstract class particulary if the class already has a parent.

But in some cases when the class should be the base class of a family of related classes, it does make senses to uses abstract classes as it would be possible to share part of the implementation.

You cannot instantiate an abstract class but you instantiate a class that derive from one provided that you have overwrote any abstract method. This is pretty basic OOP. It allows polymorphism.


这篇关于为什么我们使用抽象句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆