interface

Method return type to fulfill multiple interfaces

只谈情不闲聊 提交于 2019-12-20 11:38:38
问题 Is it possible to specify a method which returns a object that implements two or multiple interfaces? Say we have the following interfaces: interface FooBar { [Foo] & [Bar] getFooBar(); } interface Foo { void doFoo(); } inteface Bar { void doBar(); } Implementors of FooBar need to provide the method getFooBar() that returns an instance of a type which fullfills Foo as well as Bar . What I tried so far is to do it with generics: interface FooBar { <T extends Foo & Bar> T getFooBar() } class

How can a singleton class use an interface?

心不动则不痛 提交于 2019-12-20 10:57:29
问题 I read at many places that singletons can use interfaces. Some how I am unable to comprehend this. 回答1: Every class can implement an interface, and a Singleton is just a "normal" class that makes sure that only one instance of it exists at any point in time apart from the other business logic it may implement. This also means that a Singleton has at least 2 responsibities and this is not good OO design as classes should only have 1 responsibility and make sure they are good at that

Do interface variables have value-type or reference-type semantics?

孤街醉人 提交于 2019-12-20 10:24:01
问题 Do interface variables have value-type or reference-type semantics? Interfaces are implemented by types, and those types are either value types or reference types. Obviously, both int and string implement IComparable , and int is a value type, and string is a reference type. But what about this: IComparable x = 42; IComparable y = "Hello, World!"; (The question I was trying to answer was presumably deleted because it asked whether interfaces are stored on the stack or the heap, and, as we

Java Generic Interface vs Generic Methods, and when to use one

╄→гoц情女王★ 提交于 2019-12-20 09:56:07
问题 I was wondering, aside from syntactic difference, when would one use a generic interface over a method that accepts a generic parameter? public interface Flight<T>{ void fly(T obj); } over public interface Flight{ void <T> fly(T obj); } 回答1: If you declare a generic method , you always let the caller decide, which type arguments to use for the type parameters. The implementation of the method must be able to deal with all possible types arguments (and it doesn’t even have a way to ask for the

What is the purpose of checking self.__class__ ? - python

限于喜欢 提交于 2019-12-20 09:37:22
问题 What is the purpose of checking self.__class__ ? I've found some code that creates an abstract interface class and then checks whether its self.__class__ is itself, e.g. class abstract1 (object): def __init__(self): if self.__class__ == abstract1: raise NotImplementedError("Interfaces can't be instantiated") What is the purpose of that? Is it to check whether the class is a type of itself? The code is from NLTK's http://nltk.googlecode.com/svn/trunk/doc/api/nltk.probability-pysrc.html

What are some basic tenets of interface design? [closed]

≯℡__Kan透↙ 提交于 2019-12-20 09:24:53
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I am putting together some mock-ups of my first real interface and I am left wondering: What are some basic tenets of good user interface design? I am looking for something like a bullet list summary and maybe some resources that might be useful for each tenet. 回答1: "Don't make me

Inherit from a generic base class, apply a constraint, and implement an interface in C#

大城市里の小女人 提交于 2019-12-20 09:13:45
问题 This is a syntax question. I have a generic class which is inheriting from a generic base class and is applying a constraint to one of the type parameters. I also want the derived class to implement an interface. For the life of me, I cannot seem to figure out the correct syntax. This is what I have: DerivedFoo<T1,T2> : ParentFoo<T1, T2> where T2 : IBar { ... } The first thing that came to mind was this: DerivedFoo<T1,T2> : ParentFoo<T1, T2> where T2 : IBar, IFoo { ... } But that is incorrect

Optional parameters for interfaces

不打扰是莪最后的温柔 提交于 2019-12-20 09:11:25
问题 Using c# 4.0 -- building an interface and a class that implements the interface. I want to declare an optional parameter in the interface and have it be reflected in the class. So, I have the following: public interface IFoo { void Bar(int i, int j=0); } public class Foo { void Bar(int i, int j=0) { // do stuff } } This compiles, but it doesn't look right. The interface needs to have the optional parameters, because otherwise it doesn't reflect correctly in the interface method signature.

IList<T> and IReadOnlyList<T>

谁说我不能喝 提交于 2019-12-20 09:10:52
问题 If I have a method that requires a parameter that, Has a Count property Has an integer indexer (get-only) What should the type of this parameter be? I would choose IList<T> before .NET 4.5 since there was no other indexable collection interface for this and arrays implement it, which is a big plus. But .NET 4.5 introduces the new IReadOnlyList<T> interface and I want my method to support that, too. How can I write this method to support both IList<T> and IReadOnlyList<T> without violating the

Jquery ui - sortable: drag by icon 'handle' within sortable element

房东的猫 提交于 2019-12-20 09:08:35
问题 I have jquery ui sortables working fine but my sortable elements have other interactive elements within them. In order to prevent accidental sorting when interacting with the elements within the sortable divs, I'd like to somehow make the dragging movement for the sortables only occur when dragging a certain element within the sortable, such as a 'move' icon that might reside in the top left corner of each sortable. Is this possible with generic jqui, or would I need to write my own hook? 回答1