真的是接口和抽象类做抽象(隐藏工作函数) [英] Do really interface and abstract class do abstraction (hide working function)

查看:85
本文介绍了真的是接口和抽象类做抽象(隐藏工作函数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,抽象隐藏了它的工作方式(重要的是它是什么而不是如何)。



在界面中,所有方法都是抽象的,在抽象类中很少方法是抽象的,它必须在具体的类中实现或扩展。因此,实现或扩展类的任何方式都知道它的功能,因此java编程中抽象的含义是什么。或者为谁隐藏工作功能。



我尝试过:



请用实时示例清除我的疑问。(对不起,如果这是一个简单的问题)

解决方案

<接口和抽象类概念中的blockquote> abstract 抽象无关,用于安排计算机系统的复杂性。



抽象技术(OOPS的支柱之一)不一定是隐藏任何东西,而是关于建立一个人与系统交互的复杂程度,抑制比当前水平更复杂的细节。它就像一辆汽车:你知道它是由块组成的:一个座位区,一个行李箱区,一个引擎,一个制动系统,一个转向系统,因为这是一个抽象的层次。大多数人与车辆相互作用 - 但实际上,它们通常不是孤立设计的:制动系统与转向和发动机相互作用以防止滑行(例如牵引力控制)等等。每个块都由更复杂的子组件构成,其中许多组件在组成整个车辆的多个系统中具有多个角色。



abstract 方法不一样 - 它们是告诉系统这些 必须 的元素的方式由类的实现提供,以便在代码中包含抽象类或接口。这更像是俱乐部的会员资格 - 俱乐部有必须遵守的规则,或者您可能不是会员。例如,工作中的茶俱乐部可能会有每月必须支付的会费才能喝茶 - 如果你不缴纳会费,你就会被扔掉,不能喝茶!当您从抽象类的接口派生时,方法,属性等是您必须遵守 - 或实际上实现 - 的规则,以便派生新类。


As of my understanding abstraction is hiding how it works(what it does matters rather than how).

In interface all methods are abstract and in abstract class few methods are abstract and it has to be implemented or extended in a concrete class .So any way the implemented or extended class know how it functions so what is the meaning of abstraction in java programming. Or for whom it hides the working function.

What I have tried:

Please do clear my doubt with a real time example.(sorry if it's a simple question)

解决方案

abstract in the concept of interfaces and abstract classes is not to do with abstraction the technique for arranging complexity of computer systems.

Abstraction the technique (one the pillars of OOPS) isn't necessarily about "hiding" anything, but about establishing a level of complexity on which a person interacts with the system, suppressing the more complex details below the current level. It's like a car: you "know" it's made of blocks: A "seating area", a "luggage area", an "engine", a "braking system", a "steering system" because that is the level of abstraction at which most people interact with a vehicle - but in reality, they are normally not designed in isolation: the braking system interacts with the steering and engine to prevent skids for example (traction control) and so forth. And each of those "blocks" is built of much, much more complex subassemblies, many of which have multiple roles in multiple systems making up the whole vehicle.

abstract methods aren't the same - they are a way of "telling" the system that these are elements that must be provided by the implementation of the class in order to include the abstract class or interface in the code. It's a lot more like a membership of a club - the club has rules that must be followed or you may not be a member. For example, the "tea club" at work may have a "dues" you must pay every month in order to drink the tea - if you don't pay your dues, you are thrown out and can't drink the tea! When you derive from an interface of abstract class, the methods, properties and so forth are the "rules" you must obey - or in fact implement - in order to derive the new class.


这篇关于真的是接口和抽象类做抽象(隐藏工作函数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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