是否可以使用接口实现抽象

Can abstraction be achieved using interfaces

在 OOP 中,抽象是指我们只向用户提供有用的细节并隐藏所有实现细节。所以,如果我有一个接口并在 class 中实现它,那么这是如何实现抽象的呢?我阅读了这篇关于“how to achieve 100% abstraction using interfaces

的文章

如果这个问题听起来离题或含糊不清,那么它确实是,我只想知道 oop 中的抽象与接口有何关系。

So, if I have an interface and I implement it in a class then how is this achieving abstraction?

因为其他代码可以使用该接口不知道它是如何实现的。您甚至可以达到使用接口的“客户端”代码完全不知道实例化了哪个 class 的地步。

意思是:你写的代码使用了List<T>,这意味着你真的不认为那个列表实际上是ArrayList还是WhatEverElseList