我有两个接口,彼此不知道。定义接口间流程的类的设计模式名称
public interface IListener
{
event SignalEventHandler SignalReceived;
}
public interface IDevice
{
Task HandleSignalAsync();
}
而不是使每个听众直接调用的装置或传递到听众设备实现,我想保持它们分离,并且分别限定流动。例如:
public class MyApplicationFlow
{
private readonly IListener _listener;
private readonly IDevice _device;
public MyApplicationFlow(IListener listener, IDevice device)
{
_listener = listener;
_device = device;
_listener.SignalReceived += ListenerOnSignalReceived;
}
private async void ListenerOnSignalReceived(object sender, SignalEventArgs args)
{
try
{
await _device.HandleSignalAsync();
// do more stuff in real scenario
args.ProgressReporter.ReportComplete();
}
catch (Exception ex)
{
args.ProgressReporter.ReportError(ex);
}
}
}
可能有几个IDevice
和IListener
实现传入流量。
的听众和设备似乎遵循适配器模式。但是MyApplicationFlow
呢?
我甚至不确定这是行为模式还是结构模式。
是否有一个用于定义对象之间流程的类的通用名称?我可以用作该模式后面类名的后缀,例如Manager
,Coordinator
,Connector
(最好是在.NET框架中已经使用的东西)。或者,因为我找不到任何东西,我在吠叫错误的树吗?有没有更好的方法来实现这种解耦?
有没有这里的模式,只是代码 –
这仅仅是依赖注入 – maccettura
不够公平 - 我想不是一切都是一个模式!任何关于如何改善这个问题的帮助?我不知道我是否理解了降价。 – Connell