interface

Covariance/Contravariance Conundrum when using generic interface constraints

柔情痞子 提交于 2020-01-03 19:35:25
问题 public interface IShape{} public class Rectangle : IShape{} public class Base{} public class Derived : Base{} public interface IFoo<out T, in U> where T : IShape where U : Base { T Convert(U myType); } public class MyFoo : IFoo<Rectangle, Derived> { public Rectangle Convert(Derived myType) { throw new NotImplementedException(); } } class Program { static void Main(string[] args) { IFoo<IShape, Base> hmm = new MyFoo(); } } Given the above code, the compiler is unable to determine how to assign

What breaks a .net binary (dll) interface

旧街凉风 提交于 2020-01-03 19:34:06
问题 Consider two .net dlls. The first, "application.dll" contains the main business logic and data access code. The second, "webservice.dll" consists mostly of WebMethods that link to objects and methods with application.dll for the purpose of providing webservice calls to existing code. What changes (e.g. add new classes, add a new field or method to an existing class etc) can and can't be made to application.dll without requiring a recompile of webservice.dll? 回答1: Most things will be fine;

How to take a subset of an object using an interface?

…衆ロ難τιáo~ 提交于 2020-01-03 18:38:10
问题 Suppose I have this class and interface class User { name: string; age: number; isAdmin: boolean; } interface IUser { name: string; age: number; } And then I get this json object from somewhere const data = { name: "John", age: 25, isAdmin: true } I want to subset data using IUser and remove the isAdmin property like this let user = subset<IUser>(data); // user is now { name: "John", age: 25 } // can safely insert user in the db My question is how do I implement that function in TypeScript?

How to take a subset of an object using an interface?

不打扰是莪最后的温柔 提交于 2020-01-03 18:38:06
问题 Suppose I have this class and interface class User { name: string; age: number; isAdmin: boolean; } interface IUser { name: string; age: number; } And then I get this json object from somewhere const data = { name: "John", age: 25, isAdmin: true } I want to subset data using IUser and remove the isAdmin property like this let user = subset<IUser>(data); // user is now { name: "John", age: 25 } // can safely insert user in the db My question is how do I implement that function in TypeScript?

Class inheriting from several Interfaces having same method signature

时光毁灭记忆、已成空白 提交于 2020-01-03 17:25:20
问题 1) How to solve this problem in Java? 2) What if only the return types are different in the interfaces? 回答1: 1) How to solve this problem in Java? Essentially, the different "versions" of the method in the respective interfaces all bind to the same implementation method. If that's what you want, fine. If you actually want a different version of the method for each interface then you are stuck. You can't do that in Java. 2) What if only the return types are different in the interfaces? If the

Go reflection with interface embedded in struct - how to detect “real” functions?

◇◆丶佛笑我妖孽 提交于 2020-01-03 13:59:58
问题 The situation I have now is the same as was asked about in this thread: Meaning of a struct with embedded anonymous interface? type A interface { Foo() string } type B struct { A bar string } Idiomatically, coming from a backround in OOP languages, what it looks like this pattern is "trying to say" to me is that B must implement interface A. But I get by now that "Go is different". So, rather than the compile-time check I expected at first, this is happy to compile with or without a func (B)

How to implement an interface in VB.Net when two methods have the same name but different parameters

纵然是瞬间 提交于 2020-01-03 10:55:22
问题 I am a C# programmer but I have to work with some VB.Net code and I came across a situation where I have two methods on an interface with the same name but different method parameters. When I attempt to implement this interface in a class, VB.Net requires explicitly declaring "Implements MethodName" after the method signature. Since both method names are identical, this is confusing the compiler. Is there a way to get around this sort of problem? I suspect this must be a common occurrence.

Multiple Class Inheritance In TypeScript

假装没事ソ 提交于 2020-01-03 08:44:11
问题 What are ways to get around the problem of only being allowed to extend at most one other class. class Bar { doBarThings() { //... } } class Bazz { doBazzThings() { //... } } class Foo extends Bar, Bazz { doBarThings() { super.doBarThings(); //... } } This is currently not possible, TypeScript will give an error. One can overcome this problem in other languages by using interfaces but solving the problem with those is not possible in TypeScript. Suggestions are welcome! 回答1: This is possible

Creating an instance of a interface in c#

↘锁芯ラ 提交于 2020-01-03 08:30:10
问题 I am using an interface in C# and rather than write an entirely new class which implements that interface is it possible to just create an object which implements that interface? The interface is defined as public interface ITokenStore { IToken CreateRequestToken(IOAuthContext context); IToken CreateAccessToken(IOAuthContext context); } And I know in java I could something like ITokenStore tokenStore = new ITokenStore() { IToken CreateRequestToken(IOAuthContext context) { IToken requestToken

Call some methods from interface without override all the methods in JAVA

混江龙づ霸主 提交于 2020-01-03 07:05:49
问题 Friends, I have an issue in Java: I'd like to implement one structure but I'm facing some difficulty in doing it, can anyone help me. interface samp1{ method1() method2() method3() } interface samp2{ method4() method5() } class Samp implements samp1,samp2 { // this class needs only method1 from interface samp1 and method 4 from interface samp2 // I don't want to override all the methods from interface } can anyone propose some solutions for this? Is there any design pattern available for this