interface

How to load php code dynamically and check if classes implement interface

天大地大妈咪最大 提交于 2020-01-24 09:16:07
问题 I'm loading a class dynamically in PHP. This file and class name are gotten out of the database. This file must contain a class and a method. I tried to solve it with an interface, but I don't really get it how I could do it the most beautiful way. What would be your suggestions? 回答1: Use class_exists() to determine if a class has been defined, method_exists() to determine if a class has a method and instanceof to determine if a class implements an interface. 回答2: To check whether a class has

Cannot convert type via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion

北城以北 提交于 2020-01-24 02:34:21
问题 In C#, if I have a parameter for a function where the parameter type is of an interface, how do a pass in an object that implements the interface. Here is an example: The parameter for a function is as follows: List<ICustomRequired> The list that I already have is as follows: List<CustomObject> exampleList CustomObject inherits from the ICustomRequired interface What is the correct syntax to pass the exampleList as a parameter? This is how I thought to do the above task: exampleList as List

Interfaces for DTOs

China☆狼群 提交于 2020-01-24 02:14:06
问题 I am currently at the beginning of developing a large web application mainly containing an Angular SPA and an OData WebAPI that has access to a backend layer. We're at an early stage and have begun to implement the first classes including a Model.dll that is in a common namespace so that it can be accessed by all layers. We are now discussing about those DTOs within the model. Some say that using interfaces is absolutely neccessary, so the code would be like this: namespace MySolution.Common

Multiple restrictions on generic type based on super and sub classes in java

淺唱寂寞╮ 提交于 2020-01-23 08:29:47
问题 I have a generic list class that implements a particular interface. The list items in the interface also implement the same interface. public abstract class List<T extends SomeInterface> implements SomeInterface { protected LinkedList<T> m_list; ... } So now I want to make a subclass of this list that stays generic but limits the items to objects that implement the SearchListItem interface: public interface SearchListItem { public String getName(); } Here's what I have for the SearchList

Describe a deeply nested array in TypeScript

狂风中的少年 提交于 2020-01-23 06:19:58
问题 How do I define a type or interface describing a deeply nested array in TypeScript? For example, let's say I am writing a function for testing a path against any number of patterns. function match(path: string, matcher: Matcher): boolean { /* ... */ } The Matcher type may be any of the following: string RegExp Matcher[] (note the self-reference) In other words, the compiler should accept the following: match('src/index.js', 'lib/**/*'); match('src/index.js', /\/node_modules\//); match('src

type casting when objects are of interface references in Java

一个人想着一个人 提交于 2020-01-23 03:33:05
问题 I am familiar with type casting in inheritance model . Let SuperClass and SubClass be parent and child classes; SuperClass superClass = new SubClass() ; -- Here the object instantiated is a subclass object ; but its reference type is SuperClass ; that is only those methods of SuperClass can be called on the subclass object ; Any methods that are not inherited/overridden in subclass cannot be called (that is any unique methods of subclass ). I observed same behavior as above if SuperClass is

Passing a channel of things as a channel of interfaces in Go

人走茶凉 提交于 2020-01-23 01:43:13
问题 My program has a pipeline structure, and I just implemented a caching filter that sends stuff directly to output if the already processed version of data is in the cache. func Run(in chan downloader.ReadyDownload) chan CCFile { out := make(chan CCFile) processQueue := make(chan downloader.ReadyDownload) go cache.BypassFilter(in, processQueue, out) // writes the cached, already processed version to out if it exists // otherwise redirects the input to processQueue go process(processQueue, out)

Is it accurate to describe dispatch in Clojure using a Protocol as 'static'?

浪尽此生 提交于 2020-01-23 01:33:51
问题 Meikel Brandmeyer wrote a post on dispatch in Clojure with the URL title Static vs Dynamic. He writes: Protocols are not the only place where we have a trade-off of static vs. dynamic. There are several places where such a trade-off can be spotted. He provides the following example of static dispatch in a protocol: (defprotocol Flipable (flip [thing])) (defrecord Left [x]) (defrecord Right [x]) (extend-protocol Flipable Left (flip [this] (Right. (:x this))) Right (flip [this] (Left. (:x this)

TypeScript: An index signature parameter must be a 'string' or 'number' when trying to use string | number

被刻印的时光 ゝ 提交于 2020-01-22 20:21:04
问题 I'm attempting to create a function to normalize my arrays and it's expecting an output object that is structured like this: { allIds: [1], byId: { 1: {...} } } OR { allIds: ['1'], byId: { '1': {...} } } I'm trying to create an interface called IOutput to cater for this. I've tried this: interface IOutput { allIds: string[] | number[] byId: { [key: number | string]: any } } But it gives me the following error An index signature parameter type must be 'string' or 'number'. ts(1023) It seems to

Enforcing serializable from an interface without forcing classes to custom serialize in C#

左心房为你撑大大i 提交于 2020-01-22 17:43:39
问题 I have an interface that defines some methods I would like certain classes to implement. public interface IMyInterface { MethodA; MethodB; } Additionally I would like all classes implementing this interface to be serializable. If I change the interface definition to implement ISerializable as below...: public interface IMyInterface : ISerializable { MethodA; MethodB; } ...all classes must now explicitly implement serialization as far as I am aware, since if you implement ISerializable you