interface

How to restrict access to mutable or immutable methods?

Hi In a new Java project I try to apply as much best practices as possible. The one I'm having problems with is immutability. Although I understood the concept and already built some immutable classes I now came to a class where I think it's more appropriate to do it as a mutable class. The main problem is that I want to hide the mutab...

A difference in style: IDictionary vs Dictionary

I have a friend who's just getting into .NET development after developing in Java for ages and, after looking at some of his code I notice that he's doing the following quite often: IDictionary<string, MyClass> dictionary = new Dictionary<string, MyClass>(); He's declaring dictionary as the Interface rather than the Class. Typically I...

Internals of "equals" in .NET

I have a foolish doubt.Generally "System.Object" implements "Equals". When I implements IEquatable interface i can give custom definition ( I believe so) to my "Equals". so the professor class implementation is equal to class Professor:System.Object,IEquatable since there are different definitions of System.Equals ,and IEquatabl...

Java: create new implementation of type at runtime?

So, I realize the answer to this is probably "it's hard", but: I've got a weird idea, and was wondering if it's possible in Java to create a method like: <T> T wrapInterface (Class<T> interfaceClass, T wrappedObject) { if (mClass.isInterface()) { //create a new implementation of interfaceClass that, in each method, //does so...

.NET: Unable to cast object to interface it implements

I have a class (TabControlH60) that both inherits from a base class (UserControl) and implements an interface (IFrameworkClient). I instantiate the object using the .NET Activator class. With the returned instance, I can cast to the UserControl base class, but not to the interface. The exception I get is below the code snipet. How do I c...

C# interface vs class access

When a class implements an Interface, is it better to access the properties and methods through the class itself or through its Interface? ...

How to use AccessibleObjectFromWindow WinAPI function in Delphi?

http://msdn.microsoft.com/en-us/library/dd317976(VS.85).aspx STDAPI AccessibleObjectFromEvent( __in HWND hwnd, __in DWORD dwObjectID, __in DWORD dwChildID, __out IAccessible **ppacc, __out VARIANT *pvarChild ); What is IAccessible** equivalent in Delphi (2009)? ...

Java Overload method with inherited interface

Hi all, i'm trying to understand java behaviour. Using this interfaces : public interface IA {} public interface IB extends IA {} public class myClass implements IB {} I'm overloading a method like this : public void method(IA a); public void method(IB b); When calling method with the following object : IA a = new myClass(); met...

How does Returning a Struct as an Interface work?

The following code works, but I can't figure out what's going on memory-wise. Where and how is the struct value t copied? interface ITest { void Hello(); } struct STest : ITest { public void Hello() { Console.WriteLine("Hello"); } } static ITest Make() { STest t = new STest(); return t; } static void Main(string[] arg...

How to apply a different attribute to an interface's member than that of the same member in a parent interface

Imagine an interface heirarchy like this: public interface IAnimal { string Color { get; } } public interface ICat : IAnimal { } In this case, ICat 'inherits' IAnimal's Color property. Is it possible to add an attribute to the ICat's Color property, without adding it to the IAnimal? The following is an example of what I am try...

Implementation difference in C#

I am a learner of C#.Can you please explain me what is the difference between assigning a collection to interface. I see some examples,initialize List<int> few = new List<int>() { 12, 123, 211, 200 }; But some assign collection to interface IList<int> someList=new List<int>(){12,23,56,78}; When would we need the later one?.Pros an...

Load different modules without changing the logic file

Hi All: Suppose I've got 2 different modules which have the uniform(same) interfaces. The files list like this: root/ logic.py sns_api/ __init__.py facebook/ pyfacebook.py __init__.py myspace/ pymyspace.py __init__.py And pyfacebook.py and pymyspace.py have the same inte...

Accessing interfaces from classes that don't implement them?

I have an interface, IFindable that is implemented by a few classes. One other World class holds a List<IFindable> items; I have set up a getItems method in my World class, to return the list of IFindables. Now, I am trying to access that list from my Default.aspx.cs class (this is a web project). Unfortunately, I don't seem to be ab...

Can you implement an interface on a Linq2Sql class?

I have an interface called IAddress, and a class called Address that handles street, city, state/province, postal code and country. I have a couple of Linq2Sql classes that has all the address information and would like to implement the interface IAddress, and pass that in to the constructor for Address that would the load the property v...

Visual studio like panels

Hello, I need to make some vertical docking/collapsible panels in the style of the Visual Studio IDE (like Solution explorer, Toolbox, Properties, etc...), does anyone know some examples or code for doing that? Thanks, R. ...

How do you hide data from all but once class?

I'm trying to fix a design flaw that I recently ran across in some of our software without re-writing the entire thing. There is a .exe which has a message listener thread that is receiving data from some server, and then writing it to a class in a seperate DLL (we'll call it StaticDataClass) that is storing all of the data it receives ...

Upcasts in COM automatic?

In COM, if I have an interface IBase and an interface IX which inherits from IBase, can I call methods of IBase through an IX pointer, and if not, why can I call Release() and AddRef() on any COM interface pointer without an upcast? ...

Force a class to override the .equals method

I have a bunch of class who implement a common interface : Command. And this bunch of class goes to a Map. To get the Map working correctly, I need to each class who implements Command to override the Object.equals(Object other) method. it's fine. But i whould like to force the overriding of equals. => Have a compilation error when ...

New Collection interfaces in C# 3.0

What are the new collection interfaces available in C# 3.0 ? In C# 2.0 IComparer IEqualityComparer IEnumerator IEnumerable ICollection IDictionary IDictionaryEnumerator IList. ...

How do I know when an interface is directly implemented in a type ignoring inherited ones?

The issue appears is when I have a class implementing an interface, and extending a class which implements an interface: class Some : SomeBase, ISome {} class SomeBase : ISomeBase {} interface ISome{} interface ISomeBase{} Since typeof(Some).GetInterfaces() returns and array with ISome and ISomeBase, i'm not able to distinguish if ISo...