interface

If the constant interface anti-pattern is such a crime, why does Swing do it?

蓝咒 提交于 2019-12-22 05:03:23
问题 I was making a swing application, and realized I had a handful of classes that needed access to the same set of constants. I couldnt bring myself to declare one the primary holder of them and place them all in there and have the others reference it; I thought, hey, I'll just have them all inherit from some common place, but Java doesnt do multiple inheritence, BUT I can put infinity interfaces on things. So the idea came to me to dump them all into an interface (it's true, it just naturally

Implementing an Interface but changing a member to be private

我的未来我决定 提交于 2019-12-22 04:56:09
问题 All members of an Interface are public by default. But there are some properties in my interface that I want to be used as private members of some subclasses that implement my interface. Is this something that can and is done or am I way off basis here. I'm working on using more Interfaces in my architecture these days so I'm not that well versed yet. 回答1: The point of interfaces is that they provide a contract that other objects can use to communicate with your object. If you change a member

Search for text across multiple m files within the Matlab user interface

时光总嘲笑我的痴心妄想 提交于 2019-12-22 04:42:21
问题 Is there a way within the matlab user interface to search for some text across multiple m-files? 回答1: Press Ctrl-Shift-f, or go to menu Edit->Find Files. You will get a nice dialog that hopefully does what you want. 来源: https://stackoverflow.com/questions/12595662/search-for-text-across-multiple-m-files-within-the-matlab-user-interface

Why shared libraries between microservices are bad?

二次信任 提交于 2019-12-22 04:35:07
问题 Sam Newman states in his book Building Microservices The evils of too much coupling between services are far worse than the problems caused by code duplication I just don't understand how the shared code between the services is evil. Does the author mean the service boundaries themselves are poorly designed if a need for a shared library emerges, or does he really mean I should duplicate the code in the case of common business logic dependency? I don't see what that solves. Let's say I have a

Is there an interface like ICollection<t>, but designed for sorted collections?

心已入冬 提交于 2019-12-22 04:31:42
问题 ...or can I use ICollection with no problem? I mean, I don't think ICollection was designed for Sorted collections because that could break an application designed for sorted or unserted ICollection objects, but I don't know. 回答1: I'd say the ICollection<T> Interface is suitable for implementation by sorted collection types, because a sorted collection can be enumerated, added to, removed from, cleared and checked for its contents. As a counter-example, the IList<T> Interface is probably not

Implementing different yet similar structure/function sets without copy-paste

♀尐吖头ヾ 提交于 2019-12-22 04:31:31
问题 I'm implementing a set of common yet not so trivial (or error-prone) data structures for C (here) and just came with an idea that got me thinking. The question in short is, what is the best way to implement two structures that use similar algorithms but have different interfaces, without having to copy-paste/rewrite the algorithm? By best, I mean most maintainable and debug-able. I think it is obvious why you wouldn't want to have two copies of the same algorithm. Motivation Say you have a

Implementing different yet similar structure/function sets without copy-paste

老子叫甜甜 提交于 2019-12-22 04:31:02
问题 I'm implementing a set of common yet not so trivial (or error-prone) data structures for C (here) and just came with an idea that got me thinking. The question in short is, what is the best way to implement two structures that use similar algorithms but have different interfaces, without having to copy-paste/rewrite the algorithm? By best, I mean most maintainable and debug-able. I think it is obvious why you wouldn't want to have two copies of the same algorithm. Motivation Say you have a

What's the right way to design my interface when I have operations that aren't supported by all implementers?

这一生的挚爱 提交于 2019-12-22 04:18:45
问题 I have an Interface and two Classes wich are implementing the Interface. public interface MyInterface { public void firstMethod(); public int secondMethod(); } public class MyClass1 implements MyInterface { public void firstMethod() {} } public class MyClass2 implements MyInterface { public void firstMethod() {} public int secondMethod() {} } The class MyClass1 is telling me to Add unimplemented methods , because the secondMethod is not implemented, OK I will do that. But the problem is that

Interface inheritance

孤者浪人 提交于 2019-12-22 04:09:08
问题 If i have an interface: interface IFoo { int Offset {get;} } can i have this: interface IBar: IFoo { int Offset {set;} } so consumers of IBar will be able to set or get? 回答1: No, you can't! (I was about to write "Yes", but after reading Anthony's post, and trying out a few tweaks, I found the answer to be NO!) class FooBar : IFoo, IBar { public int Offset{get;set;} } (Will generate a warning as Anthony points out, which can be fixed by adding the "new" keyword.) When trying out the code: IBar

System.Data.IDbCommand and asynchronous execution?

…衆ロ難τιáo~ 提交于 2019-12-22 03:54:27
问题 System.Data.SqlClient.SqlCommand has methods BeginExecuteNonQuery BeginExecuteReader BeginExecuteXmlReader and EndExecuteNonQuery EndExecuteReader EndExecuteXmlReader for asynchronous execution. System.Data.IDbCommand only has ExecuteNonQuery ExecuteReader ExecuteXmlReader which are for synchronous operations only. Is there any interface for asynchronous operations ? In addition, why is there no BeginExecuteScalar ? 回答1: IDbCommand does not have the begin/end async methods because they did