接口和事件

编程入门 行业动态 更新时间:2024-10-24 20:11:02
本文介绍了接口和事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好,我需要一些关于接口和代表的建议。 我想在接口内定义一个委托(我知道一个 代表是一个班级,但是听我说话) 这是一个样本: 接口A B级继承接口A 程序C创建一个B类实例,需要消耗来自B类的事件 我希望B类通过 接口A来实现代表。这可能吗?这是对的吗?可以/我应该使用 抽象类吗?有更好的方法吗?

Hey everyone, I need some advice concerning Interfaces and delegates. I would like to define a delegate inside of an interface (I know a delegate is a class but hear me out) Here is a sample: Interface A Class B inherits Interface A Program C creates an instance of Class B and needs to consume events from Class B. I would like for Class B to be required to implement the delegates via Interface A. Is this possible? Is this proper? Can/Should I use an abstract class for this? Is there a better way?

推荐答案

听起来像是一个管道。我会使用 消息传递,而不是使用委托和事件。每个类都会公开一个有界队列(阻塞样式) 并在消息上有一个工作线程(或用户TP)块并处理它们需要 。 - William Stacey [MVP] < go ******** @ gmail。 COM>在留言中写道 news:11 ********************** @ f14g2000cwb.googlegr oups ...... |嘿大家,我需要一些关于接口和代表的建议。 | |我想在界面中定义一个委托(我知道一个 |委托是一个班级,但是听我说) | | |这是一个样本: | |接口A | | B类继承了接口A | |程序C创建一个B类实例,需要消耗事件 |来自B班。 | |我希望B级要求通过 |来实现代表接口A.这可能吗?这是对的吗?可以/应该使用 |抽象类为此?有更好的方法吗? | Sounds like a pipeline. Instead of using delegates and events, I would use message passing. Each class will expose a bounded queue (blocking style) and have a worker thread (or a user TP) block on messages and handle them as needed. -- William Stacey [MVP] <go********@gmail> wrote in message news:11**********************@f14g2000cwb.googlegr oups... | Hey everyone, I need some advice concerning Interfaces and delegates. | | I would like to define a delegate inside of an interface (I know a | delegate is a class but hear me out) | | | Here is a sample: | | Interface A | | Class B inherits Interface A | | Program C creates an instance of Class B and needs to consume events | from Class B. | | I would like for Class B to be required to implement the delegates via | Interface A. Is this possible? Is this proper? Can/Should I use an | abstract class for this? Is there a better way? |

William, 谢谢你。很遗憾我不知道如何实现你所说的b $ b。你可以用正确的 方向指出我(和其他人读这篇文章)吗? 问候.. " William Stacey [MVP] QUOT; <无线************ @ gmail>在消息中写道 新闻:Od **************** @ TK2MSFTNGP15.phx.gbl ... William, Thank you for that. It''s a shame I have no idea how to implement what you are speaking of. Can you point me (and others reading this) in the right direction? Regards.. "William Stacey [MVP]" <wi************@gmail> wrote in message news:Od****************@TK2MSFTNGP15.phx.gbl... 听起来像个管道。我没有使用代理和事件,而是使用消息传递。每个类都会暴露一个有界队列(阻塞样式)并在消息上有一个工作线程(或用户TP)块并按需要处理它们 > - William Stacey [MVP] < go ******** @ gmail>在消息中写道新闻:11 ********************** @ f14g2000cwb.googlegr oups ... |嘿大家,我需要一些关于接口和代表的建议。 | |我想在界面中定义一个委托(我知道 |委托是一个班级,但是听我说) | | |这是一个例子: | |界面A | | B类继承了接口A | |程序C创建了一个B类实例,需要消耗事件 |来自B班。 | |我希望B级能够通过 |来实现代表接口A.这可能吗?这是对的吗?可以/应该使用 |抽象类为此?有更好的方法吗? | Sounds like a pipeline. Instead of using delegates and events, I would use message passing. Each class will expose a bounded queue (blocking style) and have a worker thread (or a user TP) block on messages and handle them as needed. -- William Stacey [MVP] <go********@gmail> wrote in message news:11**********************@f14g2000cwb.googlegr oups... | Hey everyone, I need some advice concerning Interfaces and delegates. | | I would like to define a delegate inside of an interface (I know a | delegate is a class but hear me out) | | | Here is a sample: | | Interface A | | Class B inherits Interface A | | Program C creates an instance of Class B and needs to consume events | from Class B. | | I would like for Class B to be required to implement the delegates via | Interface A. Is this possible? Is this proper? Can/Should I use an | abstract class for this? Is there a better way? |

< go ******** @ gmail>写道: <go********@gmail> wrote: 大家好,我需要一些关于接口和代表的建议。 我想在接口内部定义一个委托(我知道一个委托是一堂课,但是听我说了) 这是一个样本: 接口A B类继承接口A 我希望B类通过接口来实现代理答:这可能吗?这是对的吗?可以/我应该使用抽象类吗?有更好的方法吗? Hey everyone, I need some advice concerning Interfaces and delegates. I would like to define a delegate inside of an interface (I know a delegate is a class but hear me out) Here is a sample: Interface A Class B inherits Interface A Program C creates an instance of Class B and needs to consume events from Class B. I would like for Class B to be required to implement the delegates via Interface A. Is this possible? Is this proper? Can/Should I use an abstract class for this? Is there a better way?

您当然可以在界面中包含事件(而不是代理)。 它不是非常常见,但在某些情况下这是有道理的。 - Jon Skeet - < sk *** @ pobox> www.pobox/~skeet 博客: www.msmvps/jon.skeet 如果回复该组,请不要给我发邮件

You can certainly include events (not delegates) within interfaces. It''s not terribly common, but it makes sense in certain situations. -- Jon Skeet - <sk***@pobox> www.pobox/~skeet Blog: www.msmvps/jon.skeet If replying to the group, please do not mail me too

更多推荐

接口和事件

本文发布于:2023-11-04 05:38:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557093.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:接口   事件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!