about interface

T

Tony Johansson

Hi!

Here comes an easy question.

Assume a have a class that implements implicitly one or more interfaces.
I compile the code and use it and it works good.

Now to my question assume that I remove all the interfaces but keep all the
method, propery and so on that I used to implement the interfaces.

I'm just wondering if I did this would this cause any problem.
I mean the purpose of an interface is just a contract that require the class
to implement all the members in the interfaces.

//Tony
 
F

Family Tree Mike

Hi!

Here comes an easy question.

Assume a have a class that implements implicitly one or more interfaces.
I compile the code and use it and it works good.

Now to my question assume that I remove all the interfaces but keep all the
method, propery and so on that I used to implement the interfaces.

I'm just wondering if I did this would this cause any problem.
I mean the purpose of an interface is just a contract that require the class
to implement all the members in the interfaces.

//Tony

The purpose of an interface is more than just a contract of members for
a class to implement. It provides abstraction so that you can write
methods which take objects as their interface _because_ of this contract.

In other words, you don't need to write methods to handle each class
type that implements your interface, as you can just write to the
interface definition in your method.
 
A

Arne Vajhøj

Here comes an easy question.

Assume a have a class that implements implicitly one or more interfaces.
I compile the code and use it and it works good.

Now to my question assume that I remove all the interfaces but keep all the
method, propery and so on that I used to implement the interfaces.

I'm just wondering if I did this would this cause any problem.
I mean the purpose of an interface is just a contract that require the class
to implement all the members in the interfaces.

You will need to change all code that refers to the interface to use
the class instead.

But that will be going from good to bad design. So it would be a silly
thing to do.

Arne
 
T

Tony Johansson

Yes I will not do so I was just curious.

Tony

Arne Vajhøj said:
You will need to change all code that refers to the interface to use
the class instead.

But that will be going from good to bad design. So it would be a silly
thing to do.

Arne
 
P

Peter Duniho

Tony said:
Hi!

Here comes an easy question.

You've already gotten the correct straightforward answers, so let me
complicate it for you... :)
Assume a have a class that implements implicitly one or more interfaces.
I compile the code and use it and it works good.

Now to my question assume that I remove all the interfaces but keep all the
method, propery and so on that I used to implement the interfaces.

I'm just wondering if I did this would this cause any problem.

It would cause no problem at all if you did that in C# 4.0 and changed
all the client code to use "dynamic" as the type instead of the
interface name.

Of course, you really wouldn't _want_ to do that because of the overhead
of using "dynamic" and the lack of type-safety. But it could be done.

Pete
 

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