interface

Casting an object to a generic interface

I have the following interface: internal interface IRelativeTo<T> where T : IObject { T getRelativeTo(); void setRelativeTo(T relativeTo); } and a bunch of classes that (should) implement it, such as: public class AdminRateShift : IObject, IRelativeTo<AdminRateShift> { AdminRateShift getRelativeTo(); void setRelativeT...

Are there established alternatives to ISomething/ ISomethingable for interfaces?

The .NET standard of prefixing an interface name with an I seems to be becoming widespread and isn't just limited to .NET any more. I have come across a lot of Java code that uses this convention (so it wouldn't surprise me if Java used it before C# did). Also Flex uses it, and so on. The placing of an I at the start of the name smacks o...

Is there a "right" way to do inheritance in JavaScript? If so, what is it?

I have been trying to learn how to add testing to existing code -- currently reading reading Working Effectively With Legacy Code. I have been trying to apply some of the principles in JavaScript, and now I'm trying to extract an interface. In searching for creating interfaces in JavaScript, I can't find a lot -- and what I find about ...

Python inheritance - how to disable a function

In C++ you can disable a function in parent's class by declaring it as private in the child class. How can this be done in Python? I.E. How can I hide parent's function from child's public interface? ...

.NET: Select concrete classes using config file

(This question specifically in C#, but applies generally to .NET) I have a largish application that has a fairly good design, and is broken into major sections over interfaces (this was done to assist parallel development). We now have a primary set of concrete classes that implement the required interfaces, but we also have additiona...

How do I programatically interface an Excel spreadsheet?

I have a request for some contract work from an organization that uses Excel as a database and wants to do some work on the Excel data via a real database. (Yeah, I know, never mind...) The client has an Excel sheet that they use internally to keep track of some government programmes. The data from this Excel sheet used to be manually i...

abstract methods in skeletal implementations of interfaces

I was re-reading Effective Java (2nd edition) item 18, prefer interfaces to abstract classes. In that item Josh Bloch provides an example of a skeletal implementation of the Map.Entry<K,V> interface: // Skeletal Implementation public abstract class AbstractMapEntry<K,V> implements Map.Entry<K,V> { // Primitive operations ...

Should this property be part of my object's interface?

I have a property called "IsSecureConnection" that is part of my object's interface. This makes sense for most implementations of the interface, however, in some implementations I would like to make the property ReadOnly. Should I omit this property from the object's interface even though it is required by all of the implementations ...

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

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: http://stackoverflow.com/questions/239909/should-this-property-be-part-of-my-objects-interface public interface Foo{ bool MyMinimallyReadOnlyPropertyThatCanAlsoBeRea...

Why would I want to use Interfaces?

I understand that they force you to implement methods and such but what I cant understand is why you would want to use them. Can anybody give me a good example or explanation on why I would want to implement this. ...

Mandatory cloneable interface in Java

Hi everybody, I'm having a small problem in Java. I have an interface called Modifiable. Objects implementing this interface are Modifiable. I also have a ModifyCommand class (with the Command pattern) that receive two Modifiable objects (to swap them in a list further on - that's not my question, I designed that solution already). Th...

How do you balance Framework/API Design and TDD

We are building a framework that will be used by other developers and for now we have been using a lot of TDD practices. We have interfaces everywhere and have well-written unit tests that mock the interfaces. However, we are now reaching the point where some of the properties/methods of the input classes need to be internal, and not v...

Attributes on an interface

I have a interface that defines some methods with attributes. These attributes need to be accessed from the calling method, but the method I have does not pull the attributes from the interface. What am I missing? public class SomeClass: ISomeInterface { MyAttribute GetAttribute() { StackTrace stackTrace = new StackTra...

C# Interface Implementation relationship is just "Can-Do" Relationship?

Today somebody told me that interface implementation in C# is just "Can-Do" relationship, not "Is-A" relationship. This conflicts with my long-time believing in LSP(Liskov Substitution Principle). I always think that all inheritance should means "Is-A" relationship. So, If interface implementation is just a "Can-Do" relationship. What ...

Re-implementing an interface that another interface already inherits

I see stuff like this a lot: interface A { ... } interface B : A { ... } class C : B, A { ...} Why would you specify that C implements interface A, when B already inherits A? Does it make any semantic difference or is it just a matter of style? (One of many examples is List<T> implementing IList<T> and ICollection<T>, while IList<T> ...

WPF HiercharchicalDataTemplate.DataType: How to react on interfaces?

Problem I've got a collection of IThings and I'd like to create a HierarchicalDataTemplate for a TreeView. The straightforward DataType={x:Type local:IThing} of course doesn't work, probably because the WPF creators didn't want to handle the possible ambiguities. Since this should handle IThings from different sources at the same time,...

Is this a bug in Delphi 2009?

It certainly looks like a bug, but I only have the trial version so it may have been fixed. ITestInterface = interface ['{9445CED8-4DBA-4EDB-9897-60980B438BE4}'] procedure Foo1; procedure Foo2; end; TTest = class(TInterfacedObject, ITestInterface) end; The above will rightly not compile. but the following does! ITestInterface...

Can the behavior for == be defined for an interface reference?

If an interface inherits IEquatable the implementing class can define the behavior of the Equals method. Is it possible to define the behavior of == operations? public interface IFoo : IEquatable {} public class Foo : IFoo { // IEquatable.Equals public bool Equals(IFoo other) { // Compare by value here...

.config to constructor tricks?

I'm working on a quick project to monitor/process data. Essentially that's just monitors, schedules and processors. The monitor checks for data (ftp, local, imap, pop, etc) using a schedule and sends new data to a processor. They call have interfaces. I'm trying to find a sane way to use config to configure what schedule/processor each ...

Is there a benefit to having both an abstract class and an interface?

I started out with a generic interface called ILogin. The interfaces requires that you implement two properties: UserID and Password. I have many login-type classes that implement this interface. As my project grew and grew, I found that many classes repeated the UserID and Password code. Now I decide that I need a base Login class. ...