java中的抽象与抽象 [英] Abstraction and abstract in java

查看:25
本文介绍了java中的抽象与抽象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名 java 开发人员,对面向对象的概念有很好的理解(或者,我认为是这样的).现在我正在学习设计模式(从头开始设计模式).我一直在阅读有关 OOPS 概念抽象的内容以简要了解它,阅读更多有关它的内容使我比之前更加困惑.

I am a java developer with good understanding of Object orientation concepts(or maybe, I think like that). And right now I am learning design patterns (From Head first design patterns). I have been reading about OOPS concept abstraction to understand it briefly, and reading more about it has made me more confusing than I earlier was.

据我所知,抽象是指隐藏程序的内部细节,同时将接口暴露给其他程序员,而不用担心内部细节.但是,我不明白

As I understand, abstraction refers to hiding the internal details of the program while exposing the interface to other programmers without worries of internal details. But, I don't understand

  1. 抽象类如何适应这种抽象概念,其中抽象类要求我实现抽象方法,在java中使用抽象类的抽象在哪里.
  2. 我觉得,实现抽象的一种方法是通过私有构造函数并要求类的用户使用工厂方法来获取类的对象,您可以在其中实现和隐藏实现细节.

如果我哪里错了,请纠正我.

Please correct me, If I am wrong anywhere.

推荐答案

抽象"是具体"的反义词.通过抽象,您可以表示概念和想法,而不是这些想法的具体实现方式.这符合你对抽象的理解——你隐藏了细节,只显示了界面.

"Abstract" is an antonym of "concrete". With abstractions you represent notions and ideas, rather than the concrete way these ideas are implemented. This fits into your understanding of abstraction - you are hiding the details and you only show the interface.

但这也适用于抽象类——它们不是具体的(它们不能被实例化,例如),并且它们没有指定实现.它们指定子类必须处理的抽象想法.

But this also fits with abstract classes - they are not concrete (they can't be instantiated, for one), and they don't specify implementations. They specify abstract ideas that subclasses have to take care of.

所以它基本上是一个不同的观点——一个是从 API 的客户端的角度来看,另一个也是关于子类的.(请注意,在某些情况下您可以使用抽象类代替接口来达到相同的效果,尽管这不被认为是一种好的做法)

So it is basically a different point of view - one is from the point of view of clients of the API, and the other is also about subclasses. (Note that you can use abstract classes instead of interfaces in some cases to achieve the same effect, although it's not considered good practice)

这篇关于java中的抽象与抽象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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