问题标签 [interface-implementation]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - 找到实现接口的正确属性
因此,我认为我有一个解决方案,可以在拥有具体类时获取 PropertyInfo,并为由具体类实现的接口获取 PropertyInfo。这是代码:
不幸的是,我发现了一个失败的案例,我不确定如何解决这个问题。所以我在一个 dll 中有一个类:
然后在另一个dll中我这样做:
现在
知道如何将 ConfigId 属性与基类属性定义匹配吗?
PS。我在具体的类属性上有属性,这就是我需要获取这些属性的原因。
任何帮助表示赞赏!
c++ - 如何制作我的“自己的”模板地图?
我想实现我自己的“简单”容器,该容器将具有地图属性但也保持插入顺序。我听说过 boost::multi_index 但我发现很难理解我想要什么。
所以我做了一个模板类:
只是为了测试它,我想做这样的事情:
但是我在插入(和 [])时不断收到编译错误,因为它将我的 KEY 转换为 basic_string 而不是字符串。这让我发疯,我找不到任何答案(或任何词来正确描述我的问题以寻找答案)。我想这与分配器有关,但我无法理解如何解决它。我怎样才能让我的地图进行这种转换,但又保持通用,因为我需要它与其他(自己实现的)类?
编辑:解决“字符串”问题后,我在传递 int 时遇到问题,因为它正在等待 &int。遵循 kebs 的建议并实现了 vector> 并摆脱了转换问题... :)
entity-framework - DbContext 如何实现 IObjectContextAdapter 但没有公共 ObjectContext 属性
在实体框架中,DbContext 类实现了 IObjectContextAdapter 接口。当我查看此界面时,我看到只有一个属性
但是 DbContext 类本身没有该属性。现在:
- 它是如何工作的?编译器不应该强制 DbContext 类具有公共 ObjectContext 属性吗?
- 或者换一种说法:为什么我必须将 DbContext 强制转换为 ObjectContextAdapter 才能访问 ObjectContext 属性。
这里发生了什么?
c# - 如果两个类没有实现相同的接口,则给出编译时错误
假设,我有一个抽象类 2 接口:
现在,假设我有两个实现这些接口的类:
现在的问题是,由于这些类实现了相同的抽象类(Entity
),因此可以Bar
与之交互,Foo
反之亦然,如下所示:
但是现在,我希望Foo
只能与另一个实例交互IFoo
并在它尝试与实例交互时给出编译时错误Bar
,同样的规则也应该适用Bar
。所以应该是这样的..
有可能做这样的事情吗?如果是这样,我该怎么做?
c++ - C++ 类头文件和实现错误
我最近才开始在 C++ 中处理单独的类文件,这是我的第一次尝试:
首先,我创建了一个名为“ThisClass.h”的类头:
然后,我在一个名为“ThisClass.cpp”的文件中实现了我的类:
最后,我创建了一个名为“main.cpp”的文件,并在其中使用了该类:
然后我通过使用 MinGW 编译器的 Code Blocks 编译并运行该程序并收到以下错误:
我在某种程度上做错了吗?任何帮助,将不胜感激。
java - 自动生成Java接口的实现类
我使用 Spring Data Repository 对多个数据存储(关系数据库、mongodb 和 elasticsearch)进行基本的 CRUD 操作。根据我的理解,它不需要用户提供存储库的实现,它就像一个魅力。
Spring Data 如何生成 Repository 的实际实现?在什么阶段完成以及如何完成?
我问这个是为了使用相同的方法为我的自定义接口生成实现类。
php - How to automatically bind implementations in PHP?
So I am a laravel developer and even though I have worked with it for a while now, and I love how the magic happens beneath the surface, how it automatically binds implementations when instantiating classes via the IoC container, right now I am trying to go to the basics of design patters and learn how things actually work.
So I started with the Animal example:
So I am reading Head First Design Patterns and I am trying to make the most of the book. At this point every time I create a new Animal, I will have to implement the make sound method which will differ in most cases.
So the book tells me that I should code a Soundable interface and then have implementations of that interface in the Animal extended classes.
I finally came up with something like this:
So now when I have another animal that barks or meows, I can simple instantiate that implementation while making an animal.
Now my question is how do I tell PHP to automatically pass the new Bark()
while instantiating the Dog
class since it will bark and I don't want to write it every time I instantiate a new Dog
object.
So how do I use a similar magic that Laravel uses to pass the Bark object automatically while instantiating Dog.
PS: I am still learning so I might be going in the wrong direction altogether while understanding these principles. Please guide me if you know better.
typescript - 一个类什么时候应该实现一个接口?
在一个项目上工作并看到开发人员在 typescript 中执行以下操作。
想知道它是否是正确的做事方式。如果类中没有实现,这似乎毫无意义。然后在我们的 React 组件中有对接口或类的引用。想要开始建立一些约定,但想要在这种情况下的正确做法方面获得一些帮助?
javascript - DOM 接口:继承与实现
在 MDN 的多个地方,像这里有这样的引号
从其父节点 Node继承属性,并实现ChildNode 接口。
这里的继承和实现有什么区别?我对接口实现接口感到困惑。父接口和实现接口是什么意思?
我想映射 DOM 树以更好地了解哪个接口来自 javascript 中的哪个属性。
java - 我们可以在 Spring 中自动装配一个没有任何实现的接口吗?
我们必须与合作伙伴共享我们的代码库以进行开发,但我们不想透露某些服务的实现。
假设我们有一个接口FooService
及其实现FooServiceImpl
。
许多其他类自动装配此服务并调用 doSomething()。例如:
如果我只是 delete FooServiceImpl
,当然NoSuchBeanException
会在启动时抛出 a 。如果我在任何地方都使用@Autowired(required = false)
FooService 自动装配,那么每当调用NullPointerException
时都会在运行时抛出a 。doSomething()
除了手动删除 FooServiceImpl 中的每个方法体之外,还有其他方法可以解决这个问题吗?
任何帮助表示赞赏。