抽象和抽象在java中 [英] Abstraction and abstract in java

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

问题描述

我是一名 java 开发人员,他非常了解面向对象的概念(或者,我认为就像那样)。现在我正在学习设计模式(From Head first design patterns)。
我一直在阅读有关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天全站免登陆