Actionscript-3和其他语言中接口存在的原因是什么? [英] What's the reason for interface to exist in Actionscript-3 and other languages

查看:136
本文介绍了Actionscript-3和其他语言中接口存在的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个接口是什么意思?即使我们在一个类上实现了一个接口,每次我们在一个不同的类上实现它时,我们也必须一次又一次地声明它的功能,那么as3或其他具有接口的语言上存在什么接口的原因。
谢谢

解决方案

我基本同意迄今为止发布的答案,只是有点补充。首先回答简单的部分,是的其他语言有接口。爪哇马上想到,但我敢肯定,所有的OOP语言(C ++,C#等)包括一些机制来创建接口。

正如杰克所说,你可以将界面写成合同,以便分离工作。假设我正在处理A,而您正在处理C,而bob正在处理B中。如果我们将B'定义为B的接口,则可以快速且相对容易地定义B'(相对于定义B,实施),都走了。我可以假设从AI可以编码到B',你可以从C中假设你可以编码到B',而当bob完成B时,我们可以插入它。



Jugg1es说到这一点。通过依赖注入(如果你不知道这个短语,请google),就可以更换整个功能块。这是描述的确切的东西,你创建一个接口,通常定义什么东西会做,比如数据库连接器。对于所有数据库连接器,您希望它能够连接到数据库并运行查询,因此您可以定义一个接口,指出类必须具有connect()方法和doQuery(stringQuery)。现在让我们来说一下Bob为MySQL数据库写的实现,现在你的客户说我们刚刚为新服务器支付了20万,他们将运行Microsoft SQL,以便利用你的软件利用这一点,所有你需要做的就是换出数据库连接器。



在现实生活中,我有一个在芝加哥经营肉类包装/分销公司的朋友。这家公司为了扫描软件包而进行软件/硬件设置,并在进出库存时对它们进行权衡,告诉他们必须升级到更新的操作系统/服务器和更新的硬件才能与软件保持同步。该软件不是以模块化方式编写的,可以保持向后兼容性。我曾经在这艘船上待过很多次,告诉某人xyz需要升级才能获得abc的功能,这将使我的工作变得容易90%。无论如何猜测在现实世界中的人们并不总是利用这些东西,它可以咬你的屁股。


what is the meaning of this interfaces? even if we implement an interface on a class, we have to declare it's functionality again and again each time we implement it on a different class, so what is the reason of interfaces exist on as3 or any other languages which has interface. Thank you

解决方案

I basically agree with the answers posted so far, just had a bit to add.

First to answer the easy part, yes other languages have interfaces. Java comes to mind immediately but I'm pretty sure all OOP languages (C++, C#, etc.) include some mechanism for creating interfaces.

As stated by Jake, you can write interfaces as "contracts" for what will be fulfilled in order to separate work. To take a hypothetical say I'm working on A and you're working on C, and bob is working on B. If we define B' as an interface for B, we can quickly and relatively easily define B' (relative to defining B, the implementation), and all go on our way. I can assume that from A I can code to B', you can assume from C you can code to B', and when bob gets done with B we can just plug it in.

This comes to Jugg1es point. The ability to swap out a whole functional piece is made easier by "dependency injection" (if you don't know this phrase, please google it). This is the exact thing described, you create an interface that defines generally what something will do, say a database connector. For all database connectors, you want it to be able to connect to database, and run queries, so you might define an interface that says the classes must have a "connect()" method and a "doQuery(stringQuery)." Now lets say Bob writes the implementation for MySQL databases, now your client says well we just paid 200,000 for new servers and they'll run Microsoft SQL so to take advantage of that with your software all you'd need to do is swap out the database connector.

In real life, I have a friend who runs a meat packing/distribution company in Chicago. The company that makes their software/hardware setup for scanning packages and weighing things as they come in and out (inventory) is telling them they have to upgrade to a newer OS/Server and newer hardware to keep with the software. The software is not written in a modular way that allows them to maintain backwards compatibility. I've been in this boat before plenty of times, telling someone xyz needs to be upgraded to get abc functionality that will make doing my job 90% easier. Anyhow guess point being in the real world people don't always make use of these things and it can bite you in the ass.

这篇关于Actionscript-3和其他语言中接口存在的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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