interface

Programming against interfaces: Do you write interfaces for all your domain classes?

Hi, I agree, that programming against interfaces is a good practice. In most cases in Java "interface" in this sense means the language construct interface, so that you write an interface and an implementation class and that you use the interface instead of the implementation class most of the time. I wonder if this is a good practice ...

How to mock with static methods?

I'm new to mock objects, but I understand that I need to have my classes implement interfaces in order to mock them. The problem I'm having is that in my data access layer, I want to have static methods, but I can't put a static method in an interface. What's the best way around this? Should I just use instance methods (which seems ...

Ideal user feedback for HTML input

Let's face it: writing proper, standards compliant HTML is quite difficult to do. Writing semantic HTML is even more so, but I don't think it's possible for a computer to figure that out. So my question to you is what would the "ideal" feedback for a user who entered HTML be? Would it be a W3C validator style list of errors and correspo...

Interface questions.

Hello, suppose that i have interface MyInterface and 2 classes A, B which implements MyInterface, i declared 2 objects MyInterface a = new A() , and MyInterfave b = new B(). when i trying to pass a to function - function doSomething(A a){} i am getting error. This is my code: public interface MyInterface { } public class A impleme...

Methods in a Java interface with or without public access modifier

Should methods in a Java interface be declared with or without a public access modifier? Technically it doesn't matter of course. A class method that implements an interface is always public. But what is a better convention? Java itself is not consequent in this. See for instance Collection vs. Comparable or Future vs. ScriptEngine. ...

What is the difference with these two sets of code

What is the difference between these two pieces of code type IInterface1 = interface procedure Proc1; end; IInterface2 = interface procedure Proc2; end; TMyClass = class(TInterfacedObject, IInterface1, IInterface2) protected procedure Proc1; procedure Proc2; end; And the following : type IInterface1 ...

Interface "recursion" and reference counting

I have a small problem with interfaces. Here it is in Pseudo code : type Interface1 = interface end; Interface2 = interface end; TParentClass = class(TInterfacedObject, Interface1) private fChild : Interface2; public procedure AddChild(aChild : Interface2); end; TChildClass = class(TInterfacedObject, Interfa...

Ruby and duck typing: design by contract impossible?

Method signature in Java: public List<String> getFilesIn(List<File> directories) similar one in ruby def get_files_in(directories) In the case of Java, the type system gives me information about what the method expects and delivers. In Ruby's case, I have no clue what I'm supposed to pass in, or what I'll expect to receive. In Ja...

Multiple Inheritance in C#

Since multiple inheritance is bad (it makes the source more complicated) C# does not provide such a pattern directly. But sometimes it would be helpful to have this ability. For instance I'm able to implement the missing multiple inheritance pattern using interfaces and three classes like that: public interface IFirst { void FirstMetho...

How to convert VB.net interface with enum to C#

I have the following VB.net interface that I need to port to C#. C# does not allow enumerations in interfaces. How can I port this without changing code that uses this interface? Public Interface MyInterface Enum MyEnum Yes = 0 No = 1 Maybe = 2 End Enum ReadOnly Property Number() As MyEnum End In...

Using explicit interfaces to ensure programming against an interface.

I have seen arguments for using explicit interfaces as a method of locking a classes usage to that interface. The argument seems to be that by forcing others to program to the interface you can ensure better decoupling of the classes and allow easier testing. Example: public interface ICut { void Cut(); } public class Knife : ICut...

Design of inheritance for Validate interfaces

I've never been so good at design because there are so many different possibilities and they all have pros and cons and I'm never sure which to go with. Anyway, here's my problem, I have a need for many different loosly related classes to have validation. However, some of these classes will need extra information to do the validation. I ...

Interface Design Question

I asked this question a while back and basically the project almost consists of reproducing excel in the browser. We want people to input data in an excel-like way. The question i have is, what is the best control to use? Should i use a regular table, and then append columns to it, or should i use a datagrid and flip it XtoY? What ap...

Deriving COM interfaces in .NET

This is complicated, at least for me, so please bare with me. I'll also preface with I've spent a day searching, to no avail. Due to company constraints out of my control, I have the following scenario: A COM library that defines the following interface (no CoClass, just the interface): [ object, uuid(xxxxxxxx-xxxx-xxxx-xxxx-...

Why an abstract class implementing an interface can miss the declaration/implementation of one of the interface's methods?

A curious thing happens in Java when you use an abstract class to implement an interface: some of the interface's methods can be completely missing (i.e. neither an abstract declaration or an actual implementation is present), but the compiler does not complain. For example, given the interface: public interface IAnything { void m1()...

.NET inheritance with generic interfaces

Hallo i am currently playing around with castle projects ActiveRecord and the remoting facility. my current problem is that i need the find a way the implement the save sub from IBaseRepository in my address class and i dont know how. here is my current code, VS tells me on the line "implements IAddress" that i have to implement Sub Sa...

Why can final constants in Java be overriden?

Consider the following interface in Java: public interface I { public final String KEY = "a"; } And the following class: public class A implements I { public String KEY = "b"; public String getKey() { return KEY; } } Why is it possible for class A to come along and override interface I's final constant? Tr...

Interface too general

In the Java code I'm working with we have an interface to define our Data Access Objects(DAO). Most of the methods take a parameter of a Data Transfer Object (DTO). The problem occurs when an implementation of the DAO needs to refer to a specific type of DTO. The method then needs to do a (to me completely unnecessary cast of the DTO to ...

Should a method that implements an interface method be annotated with @Override

Intro My real question is about the use of the annotation. Trying to find an answer myself, I ran into several other questions. This is why there are also related questions below. I hope this is not too confusing. Question Should a method that implements an interface method be annotated with @Override? Eclipse for instance automatical...

Interface Contract, Class Object?

Is contract to interface as object is to class? What is the need to differentiate identical things like this, from the code to the executing code? I sort of get the idea behind naming a class a class and the instantiated executing class an object, but overall, is that the only reason for these semi-redundant terms? ...