简体   繁体   English

是还是不是? 我可以在不同的程序集中划分接口和实现类吗?

[英]Yes or No? Can I divide interface and implementing classes in different assemblies?

I'm new at programming, but I am doing my best to learn! 我是编程新手,但我正在尽力学习!

I have an application where i have to inject an IView into my ViewModel. 我有一个应用程序,我必须将IView注入我的ViewModel。 This means the IView interface should be located in the ViewModel assembly, and not in the View one, or i'd break MVVM rules adding a reference from VM to View assembly. 这意味着IView接口应该位于ViewModel程序集中,而不是View View中,或者我打破MVVM规则,从VM添加引用到View程序集。

So my question is: is it absurd to divide interface and implementing classes in two different assemblies, or is this the right way to proceed? 所以我的问题是:在两个不同的程序集中划分接口和实现类是否荒谬,或者这是正确的方法吗?

Thank you all very much! 非常感谢你们!

is it absurd to divide interface and implementing classes in two different assemblies, 将界面划分并在两个不同的程序集中实现类是荒谬的,

No, it is quite common. 不,这很常见。 It already happens when your classes implement INotifyPropertyChanged for instance. 例如,当您的类实现INotifyPropertyChanged时,它就已经发生了。

In WCF it is a (recommended) practice to put the Service interfaces in a separate assembly (ie in an assembly that contains only interfaces). 在WCF中,(推荐)将Service接口放在单独的程序集中(即在包含接口的程序集中)。

That's precisely what an API contains. 这正是API所包含的内容。 A bunch of interfaces that you implement in order to interact with the system. 您实现的一系列接口,以便与系统进行交互。 That's the way certain artifacts (ie pluggins ) are implemented. 这就是某些工件(即插件 )实现的方式。 So it isn't absurd. 所以这并不荒谬。

As I see you put two languages on the question tag, you get another advantage with .NET. 正如我看到你在问号标签上放了两种语言,你将获得.NET的另一个优势。 You can declare your interfaces in one language and implemented them in another one. 您可以用一种语言声明接口,并在另一种语言中实现它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM