interface

Entity Framework Polymorphic associations

五迷三道 提交于 2019-12-29 04:36:07
问题 I'm going to use Entity Framework soon for a Booking System ( made from scratch ). I have been doing a few Prototypes, trying to figure out what I want to do before the project is started (I'm still discussing requirements etc. with the client). Consider this case: I have a Booking, and a booking can have associated Ressources, that can be booked, but these ressource can be different, and have different Fields etc. I have never really used EF before, so I don't know how I can achieve this

Good Case For Interfaces

不羁的心 提交于 2019-12-29 03:39:09
问题 I work at a company where some require justification for the use of an Interface in our code (Visual Studio C# 3.5). I would like to ask for an Iron Clad reasoning that interfaces are required for. (My goal is to PROVE that interfaces are a normal part of programming.) I don't need convincing, I just need a good argument to use in the convincing of others. The kind of argument I am looking for is fact based, not comparison based (ie "because the .NET library uses them" is comparison based.)

CLR implementation of virtual method calls to interface members

百般思念 提交于 2019-12-29 02:41:21
问题 Out of curiosity: how does the CLR dispatch virtual method calls to interface members to the correct implementation? I know about the VTable that the CLR maintains for each type with method slots for each method, and the fact that for each interface it has an additional list of method slots that point to the associated interface method implementations. But I don't understand the following: how does the CLR efficiently determine which interface method slot list to pick from the type's VTable?

What's the difference between an interface and an abstract class? [duplicate]

烈酒焚心 提交于 2019-12-29 02:08:21
问题 This question already has answers here : Closed 10 years ago . Duplicate: When to use an interface instead of an abstract class and vice versa? Probably one of the most famous software developer job interview questions. What would be your answer? EDIT: I'm trying to find out how you would answer this in a real-life situation. Please try to formulate your answer as you would on a real job interview (be complete, but don't be too long, post no links of course). 回答1: An interface only describes

Difference between golang pointers

天涯浪子 提交于 2019-12-29 01:56:05
问题 There are 2 kinds of variables that I have. Check for the Go playground, and I don't understand why this is happening. The problem: what I get from the Models it should be a struct to use it for GORM First() function. The code: package main import ( "fmt" ) type Test struct { Test string } var Models = map[string]interface{}{ "test": newTest(), } func main() { test1 := Test{} fmt.Println("Test 1: ") fmt.Printf("%v", test1) fmt.Println() fmt.Println("Test 1 as pointer: ") fmt.Printf("%v",

Angular 2 Injectable Interface?

房东的猫 提交于 2019-12-29 01:42:11
问题 Today I stumbled upon something that I didn't think would cause me trouble. In Java and Spring, I can declare two beans that both implement a given interface, while in another class where they are injected I only work with the interface; this is in fact what I love with IoC: you don't really have to know what object you're working with, only it's kind . So in my little Angular2/Typescript program, I was trying to do the same: webapp.module.ts: ... import { WebAppConfigurationService } from '.

Casting an object to two interfaces at the same time, to call a generic method

房东的猫 提交于 2019-12-28 13:48:39
问题 I want to call a generic method that constrains the input type T to implement two interfaces: interface IA { } interface IB { } void foo<T>(T t) where T : IA, IB { } How can I fix the last line of void bar(object obj) { if (obj is IA && obj is IB) { foo((IA && IB)obj); } } ? Reflection probably allows to do the call, but I would like to stay within the language. 回答1: Does the C# 4.0 dynamic keyword get you out of jail (mostly) free? After all - you are already doing the type checking.

Casting an object to two interfaces at the same time, to call a generic method

十年热恋 提交于 2019-12-28 13:48:12
问题 I want to call a generic method that constrains the input type T to implement two interfaces: interface IA { } interface IB { } void foo<T>(T t) where T : IA, IB { } How can I fix the last line of void bar(object obj) { if (obj is IA && obj is IB) { foo((IA && IB)obj); } } ? Reflection probably allows to do the call, but I would like to stay within the language. 回答1: Does the C# 4.0 dynamic keyword get you out of jail (mostly) free? After all - you are already doing the type checking.

Implementing Comparable with a generic class

我怕爱的太早我们不能终老 提交于 2019-12-28 12:32:29
问题 I want to define a class that implements the generic Comparable interface. While in my class I also defined a generic type element T . In order to implement the interface, I delegate the comparison to T . Here is my code: public class Item<T extends Comparable<T>> implements Comparable<Item> { private int s; private T t; public T getT() { return t; } @Override public int compareTo(Item o) { return getT().compareTo(o.getT()); } } When I try to compile it, I get the following error information:

Is it possible to make a parameter implement two interfaces?

喜你入骨 提交于 2019-12-28 12:21:32
问题 Is it possible to define a function that takes in a parameter that must implement two interfaces? (The two interfaces are ones I just remembered off the top of my head; not the ones I want to use) private void DoSomthing(IComparable, ICollection input) { } 回答1: You can: 1) Define an interface that inherits both required interfaces: public interface ICombinedInterface : IComparable, ICollection {... } private void DoSomething(ICombinedInterface input) {... } 2) Use generics: private void