interface

Should I use an interface for Type Codes?

I am working on a project that has several different codes. These codes all basically are used this way: CodeKey Description GetList GetSpecific SetProperties All of my classes implement this. I am hesitent, however, to use an interface because of one problem--the type Codes vary by type. Some are strings, some are integers, some a...

Overhead of implementing an interface

One of my colleague told me that implementing interfaces have an overhead. Is this true? I am not concerned about micro optimizations, just want to know the deeper details this entails. ...

Interfaces, inheritance and windows forms in c#

I have a design question. When writing an application where there are several components that share some attributes, and differ in others both in terms of GUI (windows forms) and back end, how would one theoretically approach this? For example, I have an application where I have 4 different types of a product. The forms for entering pro...

How to return an interface type without mentioning the derived class name?

Hi all, I'm looking for a way to not reference the class name, yet still achieve the desired effect. I can't do ITypedList.GetType() because it is an Interface. public class DerivedList : ITypedList ... public PropertyDescriptorCollection GetItemProperties() { return TypeDescriptor.GetProperties(typeof(DerivedList)); } ...

Initializing an object with references without accessing a non-default constructor

Let's suppose I have an interface named "Controller". Several classes implement this interface and I don't know these classes (e.g. the class names are located in an xml-file). Now for this Controller-implementing classes to work they have to get some references to other objects (maybe data objects). And this is my question, namely what ...

How do you define an interface, knowing that it should be immutable once published?

Anyone who develops knows that code is a living thing, so how do you go about defining a "complete" interface when considerable functionality may not have been recognised before the interface is published? ...

EJB - confused about Home/Remote -- LocalHome/Local interfaces

Revising some past exam papers for an exam mainly focus on component-oriented design and J2EE, I have come across the following question: A preliminary investigation of scenario 3: “Exchange Request” suggests that two EJBs will provide a suitable solution: a session bean called EnterExchangeRequest to control the processing and an entit...

How do I write an overload operator where both arguments are interface

I'm using interface for most of my stuff. I can't find a way to create an overload operator + that would allow me to perform an addition on any objects implementing the IPoint interface Code interface IPoint { double X { get; set; } double Y { get; set; } } class Point : IPoint { double X { get; set; } double Y { ...

Interface constraint for IComparable

When I want to constraint the type T to be comparable, should I use: where T : IComparable or where T : IComparable<T> I can't get my head around if #2 makes sense. Anyone can explain what the difference would be? ...

Abstract classes vs. interfaces vs. mixins

Could someone please explain to me the differences between abstract classes, interfaces, and mixins? I've used each before in my code but I don't know the technical differences. (And yes, I've searched, but everything I found was either too technical or otherwise unhelpful.) ...

What's the difference between interface and @interface in java?

I haven't touched Java since using JBuilder in the late 90's while at University, so I'm a little out of touch - at any rate I've been working on a small Java project this week, and using Intellij IDEA as my IDE, for a change of pace from my regular .Net development. I notice it has support for adding interfaces and @interfaces, what is...

Which interface should I expose a List<T> via?

In a response to this question runefs suggested that "unless you have a very specific reason for using IList you should considere IEnumerable". Which do you use and why? ...

Is it acceptable for interfaces to declare properties instead of methods?

Hi, Is it acceptable for interfaces to declare properties instead of methods? Which is more preferred? interface ITaggable { string GetTag(); } or interface ITaggable { Tag {get;} } Living in the .Net world. Kind regards, ...

How should I refactor this design.

How should I refactor this design? class Service : IChargeable, IExtendable<br /> { } interface IChargeable { decimal? ChargeableAmount { get; } } interface IExtendable { bool IsExtendable { get; } } class DayService : Service { } class NightService : Service { } class TwentFourService : Service { } The probl...

Using Generics in Interfaces

How do I allow my CookieData to be generic in the following code? I get an compile-time error on the declaration of ICookieService2. public struct CookieData<T> { T Value { get; set; } DateTime Expires { get; set; } } public interface ICookieService2: IDictionary<string, CookieData<T>> { // ... } My error is: The type...

Interface design? Can I do it iteratively? How should I handle changes to the interface?

Hi, What is the best approach for defining Interfaces in either C# or Java? Do we need to make generic or add the methods as and when the real need arises? Regards, Srinivas ...

Generic interface overloading for methods?

Is there a good, generic, way to do the following without resorting to a second method or lots of casts - I want to keep the API as light as possible and it seems ok to me OO-wise: class Foo { public T Bar<T>() where T: IAlpha { /* blahblahblah */ } public T Bar<T>() where T: IBeta { /* blahblahblah */ } } interfac...

Implement PHP interface such that object instance can be passed as array type argument?

In PHP it is possible to specify argument types although they call it type hinting. I am implementing an interface where one of the functions specifies an array as the argument type: function myFunction(array $argument){ } I'd like to define a class, an instance of which can be used as the argument for this function. In other words i...

DBus interface properties

How do I get the list of available DBus interface properties? I am writing a script that would be tracking specific type of usb devices connections. A way to distinguish the connections to be tracked from all usb connections I guess is to check the properties of signals' interfaces DBus is sending on a usb connection. I'd like to get th...

Is there a recognized pattern for useless objects that implement an interface?

For example, (although it's not an interface) the Stream class in .NET has an implementation provided by Stream.Null which simply discards the data. PowerShell has Out-Null. In applications I've developed, I've often found it useful to implement an interface IFoo with a default implementation NullFoo or similar when it is preferable to ...