interface

Best way to find out if an (upcast) instance doesn't implement a particular interface

Maybe the need to do this is a 'design smell' but thinking about another question, I was wondering what the cleanest way to implement the inverse of this: foreach(ISomethingable somethingableClass in collectionOfRelatedObjects) { somethingableClass.DoSomething(); } i.e. How to get/iterate through all the objects that don't implement...

Is it just me or are interfaces overused?

Ok, I may resort to a tad ranting here, so let me apologize in advance, but I'm really curious if others find this pattern annoying too (and I wonder if it is a justifiable pattern)… So, after just looking at a particular question, I noticed that almost all of the responses suggested creating an interface for injecting a mock in some te...

Is there any point for interfaces in dynamic languages?

In static languages like Java you need interfaces because otherwise the type system just won't let you do certain things. But in dynamic languages like PHP and Python you just take advantage of duck-typing. PHP supports interfaces. Ruby and Python don't have them. So you can clearly live happily without them. I've been mostly doing my ...

UML aggregation when interfaces are used

How do I represent an aggregation relation between two classes in UML, such that each class has a link to the other class's interface, not the implementing class? E.g. I have a class Foo that implements iFoo, and Bar that implements iBar. Foo should have a member variable of type iBar, and Bar should have a member variable of type iFoo....

Are delegates not just shorthand interfaces?

Suppose we have: interface Foo { bool Func(int x); } class Bar: Foo { bool Func(int x) { return (x>0); } } class Baz: Foo { bool Func(int x) { return (x<0); } } Now we can toss around Bar and Baz as a Foos and call their Func methods. Delegates simplify this a little bit: delegate bool Foo(int x); bool Bar...

Where did the concept of Interfaces come from?

In c#, we have interfaces. Where did these come from? They didn't exist in c++. ...

Testing all classes which implement an interface in Java

Is there anything out there (for Java specifically) that allow you to automatically test the behavior of an interface? As an example, let's say I have a bunch of tests for the Comparable interface, that should apply to anything that implements Comparable. What I'd like is to be able to include "ComparableTests" automatically in the test ...

.NET - Can you over interface, and when shouldn't you interface.

Is it possible to over interface? when designing an system now, I will start from interfaces and progressively write unit tests along with the interfaces until I have a pattern that works well.. I'll move onto writing some concrete classes and set the unit tests up against these.. Now I'm someone who loves interfaces, I will generally e...

How to build interface for such enum

I have the following enum: public enum Status implements StringEnum{ ONLINE("on"),OFFLINE("off"); private String status = null; private Status(String status) { this.status = status; } public String toString() { return this.status; } public static Status find(String value) { for(Status status : Status.values()) { if...

Determining the extended interfaces of a Class

I need to determine if a Class object representing an interface extends another interface, ie: package a.b.c.d; public Interface IMyInterface extends a.b.d.c.ISomeOtherInterface{ } according to the spec Class.getSuperClass() will return null for an Interface. If this Class represents either the Object class, an interf...

Interfaces: Why can't I seem to grasp them?

Could someone please demystify interfaces for me or point me to some good examples. I keep seeing interfaces popup here and there but i havent ever really been exposed to good explanations of interfaces or when to use them? I am talking about interfaces in contect to interfaces vs abstract classes ...

Bad OO design problem - I need some general functionality in Java but don't know how to implement it

Hello, I'm developping a small UML Class editor in Java, mainly a personal project, it might end up on SourceForge if I find the time to create a project on it. The project is quite advanced : I can create classes, move them around, create interfaces, create links, etc. What I'm working on is the dialog box for setting class/interface...

How to delegate interface implementation to other class in C#

Assume the following class: public class MyEnum: IEnumerator { private List<SomeObject> _myList = new List<SomeObject>(); ... } It is necessary to implement the IEnumerator methods in MyEnum. But is it possible to 'delegate' or redirect the implementation for IEnumerator directly to _myList without needing to implement the IEnume...

Why no static methods in Interfaces, but static fields and inner classes OK?

There have been a few questions asked here about why you can't define static methods within interfaces, but none of them address a basic inconsistency: why can you define static fields and static inner types within an interface, but not static methods? Static inner types perhaps aren't a fair comparison, since that's just syntactic suga...

Linq output as an Interface?

Here's the code that I'm attempting to do: public IList<IOperator> GetAll() { using (var c = new MyDataContext()) { return c.Operators.ToList(); } } Operator implements IOperator, but I'm getting the following compilation error: Cannot implicitly convert type 'System.Collections.Generic.List<MyProject.Core...

The difference between the Runnable and Callable interfaces in Java

What is the difference between using the Runnable and Callable interfaces when designing a concurrent thread in Java, why would you choose one over the other? ...

C#: Interfaces - Implicit and Explicit implementation

What are the differences in implementing interfaces implicitly and explicitly in C#? When should you use implicit and when should you use explicit? Are there any pros and/or cons to one or the other? ...

Things to consider when writing for touch screen?

I'm starting a new project which involves developing an interface for a machine that measures wedge and roundness of lenses and stores the information in a database and reports on it. There's a decent chance we're going to be putting a touch screen on this machine so that it doesn't need to have a mouse or keyboard... I don't have any ...

In what namespace should you put interfaces relative to their implementors?

Specifically, when you create an interface/implementor pair, and there is no overriding organizational concern (such as the interface should go in a different assembly ie, as recommended by the s# architecture) do you have a default way of organizing them in your namespace/naming scheme? This is obviously a more opinion based question b...

Alternatives to static methods in Java

I'm making a mini ORM for a Java program I'm writing... there is a class for each table in my db, all inheriting from ModelBase. ModelBase is abstract & provides a bunch of static methods for finding & binding objects from the db, for example: public static ArrayList findAll(Class cast_to_class) { //build the sql query & execute it ...