interface

Choose what interface to implement at runtime

≡放荡痞女 提交于 2020-01-05 04:10:06
问题 I'm wondering if, in Java, there is a way to create an object from a class implementing multiple interfaces, but choosing at runtime what interfaces should be implemented. Those interfaces would have no methods, this would be a way to create an object by defining at run time which attributes should have. That is my real problem. USE CASE: I have a class with a huge number of attributes but the objects created from this class would use only some of those attributes, some will be in common

What is the cost of ContainsAll in Java?

♀尐吖头ヾ 提交于 2020-01-04 18:21:13
问题 I discovered containsAll() (a List interface method) during some coding today, and it looks pretty slick. Does anyone know how much this costs in terms of performance/iterations? The documentation didn't offer much in terms of that. 回答1: first, it iterates each element of the supplied collection then it iterates all elements of the list and compares the current element with them using .equals(..) (Note: this is about lists, as you specified in the question. Other collections behave

What is the cost of ContainsAll in Java?

强颜欢笑 提交于 2020-01-04 18:21:06
问题 I discovered containsAll() (a List interface method) during some coding today, and it looks pretty slick. Does anyone know how much this costs in terms of performance/iterations? The documentation didn't offer much in terms of that. 回答1: first, it iterates each element of the supplied collection then it iterates all elements of the list and compares the current element with them using .equals(..) (Note: this is about lists, as you specified in the question. Other collections behave

how to create an interface around classes that already exist but cannot be modified in java

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 15:51:22
问题 Suppose I already have 2 classes in my code: class SomeOrder { String getOrderId() { return orderId; } } class AnotherOrder { String getOrderId() { return orderId; } } How to create an interface around both these classes which is: interface Order { String getOrderId(); } Ideally, I would modify the code so that SomOrder implements Order and AnotherOrder implements Order but the catch here is that they belong in a package that I cannot control or edit (i.e. they come from an external jar). My

OOP Task (class hierarchy, inheritance, interface, etc.)

两盒软妹~` 提交于 2020-01-04 13:47:19
问题 Since I am trying to learn more about OOP (Java) I'm working my way through some literature where I found this 'task'. Unfortunately I am having kind of a hard time since I am pretty new to OOP and I don't have any sample solution to this. Maybe some of you can give me some input so can work my way through this. Define a class hierarchy for these classes: quadrilateral convex quadrilateral trapezoid parallelogram rhombus rectangle square Create an instance of each class if possible Define

Moq Setup InvalidCastException when Mocking an interface that implements multiple interfaces having the same method signature

蓝咒 提交于 2020-01-04 13:45:07
问题 So I have the following code: interface Parent1 { void Foo(); } interface Parent2 { void Foo(); } interface ChildInterface : Parent1, Parent2 { } I want to mock ChildInterface and setup its Foo(). So I used Moq to do this: var c = new Mock<ChildInterface>(MockBehavior.Strict); c.Setup(p1 => ((Parent1)p1).Foo()); c.Setup(p2 => ((Parent2)p2).Foo()); It cannot just accept without doing an explicit casting. From explanations from this SO question. So I did that. And it compiles without errors !

Alternate of win32 framework for windowing system on windows

社会主义新天地 提交于 2020-01-04 13:34:43
问题 I want to develop a custom window system in c++ that should not depend on win32 library. As an example, Google Chrome has an interface that is not similar to windows own interface. Similarly MPCstar and adobe products have their own interfaces. Please help me where to start for such a project? 回答1: Qt is awesome even if you don't need cross platform support. I assure you after using it you won't understand how anyone could ever develop native GUI on frameworks like Win32 and MFC. Its only

Optimize finding all classes implementing IInterface<T> and those explicitly implementing it with a specific type

送分小仙女□ 提交于 2020-01-04 10:16:10
问题 I have an interface ISerializeDeserialize defined and some classes inheriting the generic interface. I also have some code generated assemblies using the CodeDomProvider which generates classes inherited from the same interface but implementing it with a specific Type. What I want to achieve is getting a list of the generic implementations and those implementing the specific type. You can let T=int in the code below. To get all classes implementing ISerializeDeserialize of some type I so far

How can I make an interface property optionally read-only in VB.NET?

情到浓时终转凉″ 提交于 2020-01-04 09:16:53
问题 This is a follow-up to a previous question I had about interfaces. I received an answer that I like, but I'm not sure how to implement it in VB.NET. Previous question: Should this property be part of my object's interface? public interface Foo{ bool MyMinimallyReadOnlyPropertyThatCanAlsoBeReadWrite {get;} } How can I achieve this with the VB.NET syntax? As far as I know, my only option is to mark the property as ReadOnly (I cannot implement the setter) or not (I must implement the setter).

Liskov substitution principle and Interface

三世轮回 提交于 2020-01-04 07:00:09
问题 Does the ICollection<T>.Add() -implementation of arrays break the Liskov substitution principle? The method results in a NotSupportedException , which does break the LSP, IMHO. string[] data = new string[] {"a"}; ICollection<string> dataCollection = data; dataCollection.Add("b"); This results in Unhandled exception: System.NotSupportedException: Collection was of a fixed size. I found a pretty similar question concerning Stream -implementations. I open a separate question, because this case