The 'Interface' Type - Unique to .NET?

J

Jordan

In OOP literature we read frequently about "interface" - a term which is
apparently used to mean different things depending on context and possibly
language.

..NET however provides for the Interface type - as a specific and unique type
(amongst the class, struct, enum, etc types). There is no ambiguity about
its meaning; it's a very specific thing (a .NET type) independent of
context.

My question: I am wondering of other OOP languages like Smalltalk and Java
provide an interface type as well - or if 'interface' is a type unique to
..NET.

Thanks.
 
O

Octavio Hernandez

Jordan,

Java also offers interface types, in a way very similar to .NET.
The concept of interface was first used in the language Objective C.

Regards - Octavio
 
J

John Bailo

Well, it allows for an /interface/ as in a class that can be an
interface with interface methods.

But there is (in Java) no 'interface' type or keyword.

MyClass implements MyInterface

Where MyInterface is just a class built to the rules of a java interface.
 
O

Octavio Hernandez

Thanks, John!

I've been out of the Java world for a while...

Regards - Octavio
 
P

Padu

"Jordan"
In OOP literature we read frequently about "interface" - a term which is
apparently used to mean different things depending on context and possibly
language.

.NET however provides for the Interface type - as a specific and unique
type (amongst the class, struct, enum, etc types). There is no ambiguity
about its meaning; it's a very specific thing (a .NET type) independent of
context.

My question: I am wondering of other OOP languages like Smalltalk and Java
provide an interface type as well - or if 'interface' is a type unique to
.NET.

Thanks.

Delphi implements Interfaces exactly like C#. Humnnn, I wonder if Mr.
Hejlsberg had something to do with that.

Cheers

Padu
 
J

Joanna Carter [TeamB]

"Padu" <[email protected]> a écrit dans le message de (e-mail address removed)...

| Delphi implements Interfaces exactly like C#. Humnnn, I wonder if Mr.
| Hejlsberg had something to do with that.

Not true. Delphi interfaces for Win32 are based on the COM specification
where you have a base interface type, either IUnknown or IInterface which
has _AddRef; _Release and QueryInterface methods. They are reference counted
and any class that supports interfaces can derive from TInterfacedObject
which implements those three methods. Every object has an interface table
and the addresses for each interface differ from the address of the
implementing object.

In C#, interfaces are their own type with no base definition. They don't
have any relationship to COM, unless a GUID is declared for them.
Implementing objects and all other interfaces implemented by that object all
return the same address. .NET interfaces are not reference counted, instead
they are just alternative references to an object which can be garbage
collected.

It is only with .NET that Delphi interfaces changed to follow the .NET
model.

Joanna
 
B

Bruce Wood

Not to my knowledge. AFAIK Java implements an "interface" concept very
similar to that of C#, complete with the keyword "interface".

Any O-O language that doesn't support multiple inheritance has to
support something like interfaces... single inheritance with no
interface-like concept would hog-tie the programmer.
 
J

Jon Skeet [C# MVP]

John Bailo said:
Well, it allows for an /interface/ as in a class that can be an
interface with interface methods.

But there is (in Java) no 'interface' type or keyword.

MyClass implements MyInterface

Where MyInterface is just a class built to the rules of a java interface.

No it's not. Try doing that with a class and you get the following
error: "interface expected here".

As Octavio says, Java interfaces are very like .NET interfaces.
Likewise, but have multiple inheritance of interface but single
inheritance of implementation.
 
R

Renze de Waal

John,

In the java definition it states that it is only possible to implement
an interface. Implements with a non-interface is not an option. Do you
have a java compiler that allows you to implement with a
non-interface?

After your post I tried to get the JDK to accept a class definition
that implements a class, but it won't let me do it (the error I get:
interface expected here).

Best regards,

Renze.
 
J

Jon Skeet [C# MVP]

John Bailo said:
What does 'interface' do for me that implements with an non-interface
doesn't?

Try extending multiple classes, then try implementing multiple
interfaces.

(Various things like mocking are also much easier with interfaces,
although that's a separate issue.)
 
M

Michael Voss

Bruce Wood wrote:
[...snip...]
Any O-O language that doesn't support multiple inheritance has to
support something like interfaces... single inheritance with no
interface-like concept would hog-tie the programmer.
[...snip...]

Well, Smalltalk (as a pure OO language) doesn't implement multiple
inheritance and does not know about interfaces. And I don't feel "hog-tied"
at all ;-). But then, Smalltalk isn't statically typed, so I'd like to
modify your statement:

Any statically typed language that doesn't support multiple inheritance
might benefit from something like interfaces.

Interfaces might be necessary to work around problems created by static type
checking. You will propably not need interfaces in dynamically typed
languages.
 
M

Michael Voss

Bruce Wood wrote:
[...snip...]
Any O-O language that doesn't support multiple inheritance has to
support something like interfaces... single inheritance with no
interface-like concept would hog-tie the programmer.
[...snip...]

Well, Smalltalk (as a pure OO language) doesn't implement multiple
inheritance and does not know about interfaces. And I don't feel "hog-tied"
at all ;-). But then, Smalltalk isn't statically typed, so I'd like to
modify your statement:

Any statically typed language that doesn't support multiple inheritance
might benefit from something like interfaces.

Interfaces might be necessary to work around problems created by static type
checking. You will propably not need interfaces in dynamically typed
languages.
 
O

Octavius

As others have mentioned this is 100% wrong.

Java has an 'interface' keyword.

A "class built to the rules of a java interface" is one that requires
the 'interface' keyword.


public interface TestIF {
void TestSomething();
int TestAlotOfThins();
}
 
J

John Bailo

Jon said:
Well, he's got an error in his code. I've mailed him to let him know -
I suspect if you look at the same page this time tomorrow it will have
been fixed.

Yeah, you're right -- he fixed it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top