interface

Specify that an interface can only be implemented by reference types C#

橙三吉。 提交于 2021-02-07 12:31:10
问题 If I declare an interface in C#, is there any way I can explicitly declare that any type implementing that interface is a reference type? The reason I want to do this is so that wherever I use the interface as a type parameter, I don't have to specify that the implementing type also has to be a reference type. Example of what I want to accomplish: public interface IInterface { void A(); int B { get; } } public class UsingType<T> where T : IInterface { public void DoSomething(T input) {

Inject an Interface with Angular 4

夙愿已清 提交于 2021-02-07 04:24:12
问题 I'm trying to create a generic DeleteableConfirmationComponent that will allow me to show a confirmation dialog and invoke the delete method from any injected service implementing a Deleteable infterface. To do so, I've created this Interface: export interface Deleteable { delete(object); } and I have a service that implements it: @Injectable() export class LocalityService implements Deleteable { delete(locality): Observable<Locality> { // Delete logic. } } For the

C# Interfaces: Is it possible to refer to the type that implements the interface within the interface itself?

*爱你&永不变心* 提交于 2021-02-07 03:30:38
问题 What I basically wish to do is design a generic interface that, when implemented, results in a class that can behave exactly like T, except that it has some additional functionality. Here is an example of what I'm talking about: public interface ICoolInterface<T> { T Value { get; set; } T DoSomethingCool(); } public class CoolInt : ICoolInterface<int> { private int _value; public CoolInt(int value) { _value = value; } public int Value { get { return _value; } set { _value = value; } } public

Who implements Connection, ResultSet and Statement interfaces in this java program? [duplicate]

余生颓废 提交于 2021-02-06 13:51:53
问题 This question already has answers here : JDBC- Implementation of interfaces (5 answers) Closed 1 year ago . I recently found out that the Statement, Connection and the ResultSet used in the following program are interfaces. This program works completely fine but who implements these interfaces ? package jdbc; import java.sql.*; public class Mango { public static void main(String[] args) throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con = DriverManager

What are the pros and cons of using interfaces in Delphi?

对着背影说爱祢 提交于 2021-02-05 14:51:47
问题 I have used Delphi classes for a while now but never really got into using interfaces. I already have read a bit about them but want to learn more. I would like to hear which pros and cons you have encountered when using interfaces in Delphi regarding coding, performance, maintainability, code clearness, layer separation and generally speaking any regard you can think of. Thanks and best regards 回答1: All I can think of for now: Pros: Clear separation between interface and implementation

What are the pros and cons of using interfaces in Delphi?

痴心易碎 提交于 2021-02-05 14:51:42
问题 I have used Delphi classes for a while now but never really got into using interfaces. I already have read a bit about them but want to learn more. I would like to hear which pros and cons you have encountered when using interfaces in Delphi regarding coding, performance, maintainability, code clearness, layer separation and generally speaking any regard you can think of. Thanks and best regards 回答1: All I can think of for now: Pros: Clear separation between interface and implementation

Extend interface to contain a date type

China☆狼群 提交于 2021-02-05 09:43:50
问题 I need to extend an interface in Typescript to contain a Date type. I have tried the following interface WithDate { [key: string]: Date; } But when I try to extend WithDate , I get the error: interface Person extends WithDate { id: number; // Property 'id' of type 'number' is not assignable to string index type 'Date' name: string; date: Date; } Any ideas how to fix this error? Many thanks 回答1: interface WithDate { [key: string]: Date; } With this interface you are telling TypeScript that

Extend interface to contain a date type

不羁岁月 提交于 2021-02-05 09:43:24
问题 I need to extend an interface in Typescript to contain a Date type. I have tried the following interface WithDate { [key: string]: Date; } But when I try to extend WithDate , I get the error: interface Person extends WithDate { id: number; // Property 'id' of type 'number' is not assignable to string index type 'Date' name: string; date: Date; } Any ideas how to fix this error? Many thanks 回答1: interface WithDate { [key: string]: Date; } With this interface you are telling TypeScript that

using covariance on an interface …Runtime Error Unable to cast object of type 'derviedAService ' to type 'iBaseService`1[mybase]'

女生的网名这么多〃 提交于 2021-02-05 09:43:24
问题 using System; using System.Collections.Generic; namespace mymodels { public abstract class mybase { public string v1 {get; set;} } public class derivedA : mybase { public string v2 {get; set;} } public class derivedB : mybase { public string v2 {get; set;} } } namespace myservices { interface iBaseService<T> where T : mymodels.mybase { T Get (); } public class derviedAService : iBaseService<mymodels.derivedA> { public derviedAService (){} public mymodels.derivedA Get() { mymodels.derivedA d =

using covariance on an interface …Runtime Error Unable to cast object of type 'derviedAService ' to type 'iBaseService`1[mybase]'

故事扮演 提交于 2021-02-05 09:39:59
问题 using System; using System.Collections.Generic; namespace mymodels { public abstract class mybase { public string v1 {get; set;} } public class derivedA : mybase { public string v2 {get; set;} } public class derivedB : mybase { public string v2 {get; set;} } } namespace myservices { interface iBaseService<T> where T : mymodels.mybase { T Get (); } public class derviedAService : iBaseService<mymodels.derivedA> { public derviedAService (){} public mymodels.derivedA Get() { mymodels.derivedA d =