interface

interface as return type

吃可爱长大的小学妹 提交于 2020-01-09 12:53:27
问题 Can interface be a return type of a function. If yes then whats the advantage. e.g. is the following code correct where array of interface is being returned. public interface Interface { int Type { get; } string Name { get; } } public override Interface[] ShowValue(int a) { . . } 回答1: Yes, you can return an interface. Let's say classes A and B each implement interface Ic : public interface Ic { int Type { get; } string Name { get; } } public class A : Ic { . . . } public class B : Ic . . . }

Why shouldn't C#(or .NET) allow us to put a static/shared method inside an interface?

风流意气都作罢 提交于 2020-01-09 11:14:29
问题 Why shouldn't C#(or .NET) allow us to put a static/shared method inside an interface? seemingly duplicate from here. but my idea is a bit different one, I just want to put a helper for my plugins(interface) shouldn't C# at least allow this idea? namespace MycComponent { public interface ITaskPlugin : ITaskInfo { string Description { get; } string MenuTree { get; } string MenuCaption { get; } void ShowTask(Form parentForm); void ShowTask(Form parentForm, Dictionary<string, object> pkColumns);

Why shouldn't C#(or .NET) allow us to put a static/shared method inside an interface?

久未见 提交于 2020-01-09 11:14:11
问题 Why shouldn't C#(or .NET) allow us to put a static/shared method inside an interface? seemingly duplicate from here. but my idea is a bit different one, I just want to put a helper for my plugins(interface) shouldn't C# at least allow this idea? namespace MycComponent { public interface ITaskPlugin : ITaskInfo { string Description { get; } string MenuTree { get; } string MenuCaption { get; } void ShowTask(Form parentForm); void ShowTask(Form parentForm, Dictionary<string, object> pkColumns);

What do you call it when one interface “inherits” from another?

我怕爱的太早我们不能终老 提交于 2020-01-09 04:39:22
问题 If I have class B : A {} I say that "Class B inherited class A" or "class B derives from class A". However, if I instead have: class B : ISomeInterface {} it's wrong to say "B inherits ISomeInterface" -- the proper term is to say "B implements ISomeInterface". But, say I have interface ISomeInterface : ISomeOtherInterface {} Now, it's still wrong to say "inherits", but it's now just as wrong to say "implements" since ISomeInterface doesn't implement anything. So, what do you call that

What do you call it when one interface “inherits” from another?

☆樱花仙子☆ 提交于 2020-01-09 04:39:05
问题 If I have class B : A {} I say that "Class B inherited class A" or "class B derives from class A". However, if I instead have: class B : ISomeInterface {} it's wrong to say "B inherits ISomeInterface" -- the proper term is to say "B implements ISomeInterface". But, say I have interface ISomeInterface : ISomeOtherInterface {} Now, it's still wrong to say "inherits", but it's now just as wrong to say "implements" since ISomeInterface doesn't implement anything. So, what do you call that

Cannot get interface from different process via ROT

旧时模样 提交于 2020-01-07 07:01:18
问题 my app is an .exe, it registers itself to ROT. [ComVisible(true)] [ProgId("My.App")] public class MyApp { public Interop_MyApp.IXXX XXX { get { return XXXImpl.Instance; } // -> Instance is derived from Interop_MyApp.IXXX, and static } public MyApp() { } }; I start the .exe above, it's running. Then I start an other .exe, which tries to get the XXX. object o = Marshal.GetActiveObject("My.App"); // -> returns a __ComObject, fine if (o == null) throw new InvalidOperationException("Could not

What is an interface assertion?

a 夏天 提交于 2020-01-07 04:55:11
问题 I have just came across this piece of code on this blog post type Logger interface { Debug(msg string, keyvals ...interface{}) error Info(msg string, keyvals ...interface{}) error Error(msg string, keyvals ...interface{}) error } type tmLogger struct { srcLogger kitlog.Logger } // Interface assertions var _ Logger = (*tmLogger)(nil) // What is this? // ... interface definition ... What is this "interface assertion"? 回答1: It assigns a nil pointer to a concrete type to a variable of the

Implementing an Interface with Child Classes

百般思念 提交于 2020-01-07 04:36:16
问题 I have the following interfaces: Interface IViewModel ... End Interface Interface ISpecialViewModel Inherits IViewModel ... End Interface Interface IView WriteOnly Property MyViewModel As IViewModel End Interface Following are my classes: Class VerySpecialViewModel implements ISpecialViewModel ... End Class Class View Implements IView Public WriteOnly Property MyViewModel As VerySpecialViewModel Implements IView.MyViewModel ... End Property End Class It tells me that 'MyViewModel' cannot

Extending an object vs Implementing an interface

无人久伴 提交于 2020-01-07 04:21:09
问题 Trying to understand a question I got wrong on a test: How does inheritance differ from implementing interfaces? With inheritance, a class gains behavior from its superclass. With interfaces, a class gains behavior from the interface it implements. (this is the one I chose) With inheritance, a class must implement the methods defined by its superclass. With interfaces, a class gains both instance variables and behaviors from the interface it implements. The way I was thinking is that

Why can variables be assigned to interface type?

时光总嘲笑我的痴心妄想 提交于 2020-01-07 03:03:13
问题 I'm new to Java and am trying to learn the concept of interface. I saw the code below online. I understand that interface can't be instantiated. My question is, WatchService, Path, WatchKey and WatchEvent are all interface, how come variables can be assigned to interface type? Is is the same as instantiation? import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Path; import java.nio.file.Paths; import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;