473,385 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Any good reason for NOT using interface?

As in subject.

Thanks

MH
Nov 16 '05 #1
26 2060
n!
> As in subject.

Typically you use the message body to provide a more complete description of
your question ;o)

Any good reason for not using an interface for what? I wouldn't use them for
everything. But I do use them frequently.

n!
Nov 16 '05 #2
Sorry n!, you answer do not provide anything costructive.
I only hope you were trying to help and not to use keyboard and fingers
without using brain.
But do you realy think you help me?

MH
Nov 16 '05 #3
Marius

I would say that the previous reply to your post was more constructive
then your question. Please post a proper question, stating what you are
wondering and why. If you do not want to provide more information then
what you already have done, then you will have to do with the short answer

"Yes there are good reasons for not using interfaces in SOME situations".

//Andreas

"Marius Horak" <so*****@europe.eu> skrev i meddelandet
news:uv****************@TK2MSFTNGP10.phx.gbl...
Sorry n!, you answer do not provide anything costructive.
I only hope you were trying to help and not to use keyboard and fingers
without using brain.
But do you realy think you help me?

MH

Nov 16 '05 #4

"Andreas Håkansson" <andy.h (at) telia.com> wrote in message
news:eB**************@TK2MSFTNGP09.phx.gbl...
Marius

I would say that the previous reply to your post was more constructive
then your question. Please post a proper question, stating what you are
wondering and why.
Do you mean that is I ask how to get from A to B I have to say 'what and
why' as well?
If someone does not like my question the best way is to ignore it. Or if you
feel so strongly just sue me.
So far so many characters have been used and still no good reason for not
using interface.
Please bare in mind that this is a technical NG and not general purpose.
If you do not want to provide more information then
what you already have done, then you will have to do with the short answer

"Yes there are good reasons for not using interfaces in SOME

situations".

Could you elaborate on 'in SOME situations' please?

MH

Nov 16 '05 #5
Marius,

Many of us spend our time helping people on this list, so there is no
need to be rude when someone asks you to clairify your question so a
correct answer can be given.

When to use and not to use interfaces all depends on the context of the
situation. If you for example talk about Remoting then there are pros and
cons of using interfaces. If you talk in normal OOP design, then an
interface
is usefull when a class "supports" some shared functionality so the classes
can be used in a polymorphic fashion. But then again an interface is not a
subsitute for an abstract base class. Interfaces is also the only way you
can
provide a close thing to multiple inheritence in C#.

When to use an interface depends on the context - so your easy question
is without an equality easy answer, therefor I asked you to elaborate on in
what situation you mean.

//Andreas

"Marius Horak" <so*****@europe.eu> skrev i meddelandet
news:ul**************@TK2MSFTNGP11.phx.gbl...

"Andreas Håkansson" <andy.h (at) telia.com> wrote in message
news:eB**************@TK2MSFTNGP09.phx.gbl...
Marius

I would say that the previous reply to your post was more constructive then your question. Please post a proper question, stating what you are
wondering and why.
Do you mean that is I ask how to get from A to B I have to say 'what and
why' as well?
If someone does not like my question the best way is to ignore it. Or if

you feel so strongly just sue me.
So far so many characters have been used and still no good reason for not
using interface.
Please bare in mind that this is a technical NG and not general purpose.
If you do not want to provide more information then
what you already have done, then you will have to do with the short answer
"Yes there are good reasons for not using interfaces in SOME

situations".

Could you elaborate on 'in SOME situations' please?

MH

Nov 16 '05 #6
Andreas,

"Andreas Håkansson" <andy.h (at) telia.com> wrote in message
news:uW**************@TK2MSFTNGP12.phx.gbl...
Many of us spend our time helping people on this list, so there is no
need to be rude when someone asks you to clairify your question so a
correct answer can be given.


n! did not ask me to clarify my question. He/she just did not like it.
I can bet that he/she does not do it everytime so his/her action (reaction)
is selective.

Why I asked the question?
Well, I have to maintain an old system where most of objects are based on
interface.
In one case I have to add a new parameter to one of the methods.
This interface is used as base for 42 objects but the change is relevant to
one object only.
Without interface all would be simple as the method is referenced by the
object 7 times. With interface I face changing 411 lines adding useless
parameter or to create a separate object that will be 99% like other 41
objects.
Having this experience I will never use interface in my code.

MH
Nov 16 '05 #7
Marius,

Once an interface has been published it may never be changed or
you will be breaking it. If you need to add a new parameter to an existing
interface method then you should create a second interface which contains
the new method overload and implement it. Then you have the old method
throw an NotImplementedException.

interface IFoo
{
void Foo(int a);
}

interface IFoo2
{
void Foo(int a, int b);
}

public class Bar : IFoo, IBar
{
public Bar()
{
}

// Implement IFoo.Foo(int a)
public void Foo(int a)
{
throw new NotImplementedException();
}

// Implement IFoo2.Foo(int a, int b)
public void Foo(int a, int b)
{
// Work your magic
}
}

If you look at Win32 you will see this all over the place. Infact if you
read any
books/resources on OOP you will see this.

HTH,

//Andreas

"Marius Horak" <so*****@europe.eu> skrev i meddelandet
news:O3**************@TK2MSFTNGP09.phx.gbl...
Andreas,

"Andreas Håkansson" <andy.h (at) telia.com> wrote in message
news:uW**************@TK2MSFTNGP12.phx.gbl...
Many of us spend our time helping people on this list, so there is no
need to be rude when someone asks you to clairify your question so a
correct answer can be given.
n! did not ask me to clarify my question. He/she just did not like it.
I can bet that he/she does not do it everytime so his/her action

(reaction) is selective.

Why I asked the question?
Well, I have to maintain an old system where most of objects are based on
interface.
In one case I have to add a new parameter to one of the methods.
This interface is used as base for 42 objects but the change is relevant to one object only.
Without interface all would be simple as the method is referenced by the
object 7 times. With interface I face changing 411 lines adding useless
parameter or to create a separate object that will be 99% like other 41
objects.
Having this experience I will never use interface in my code.

MH

Nov 16 '05 #8

"Andreas Håkansson" <andy.h (at) telia.com> wrote in message
news:eL**************@TK2MSFTNGP11.phx.gbl...
Marius,

Once an interface has been published it may never be changed or
you will be breaking it. If you need to add a new parameter to an existing
interface method then you should create a second interface which contains
the new method overload and implement it. Then you have the old method
throw an NotImplementedException.


And all of this fuss can be avoided by not using interface.

MH
Nov 16 '05 #9
Marius,

I am not going to preach oop to you. But if you believe that millions
of developers are totaly wrong then you are entitled to have that oppinion,
if not I recommend you pick up an oop book at your local bookstore =)

Removing the interface removes all your abilities of using polymorphism.

//Andreas

"Marius Horak" <so*****@europe.eu> skrev i meddelandet
news:us*************@tk2msftngp13.phx.gbl...

"Andreas Håkansson" <andy.h (at) telia.com> wrote in message
news:eL**************@TK2MSFTNGP11.phx.gbl...
Marius,

Once an interface has been published it may never be changed or
you will be breaking it. If you need to add a new parameter to an existing interface method then you should create a second interface which contains the new method overload and implement it. Then you have the old method
throw an NotImplementedException.


And all of this fuss can be avoided by not using interface.

MH

Nov 16 '05 #10
n!
> n! did not ask me to clarify my question. He/she just did not like it.

I'm a 'he' btw (last time I looked, anyway). :)

Anyway, I did ask:
Any good reason for not using an interface for what?
Which was basically me asking for clarification. My first sentence was a
(lame) attempt at making the mail a bit more 'friendly' (hence the smiley)
:o)
I can bet that he/she does not do it everytime so his/her action (reaction) is selective.


I replied in the way I did because there was no-way to answer your original
question without simply guessing what you actually wanted.

Your clarification asks your question much better :)

n!
Nov 16 '05 #11
n!
> > Once an interface has been published it may never be changed or
you will be breaking it. If you need to add a new parameter to an existing interface method then you should create a second interface which contains the new method overload and implement it. Then you have the old method
throw an NotImplementedException.


And all of this fuss can be avoided by not using interface.


You cannot avoid this by not using an interface. Your class definitions are
*all* contracts and claim 'I provide this' by their exposed methods and
properties. If your class changes it can still break other code (depending
on the changes you make).

In C# an interface defines a set of methods, and a class may implement
multiple interfaces. An abstract class is similar in principle but you may
not inherit multiple abstract classes (and abstract classes may provide
implementation details, whereas interfaces may not). So by defining an
interface, it allows a future object (ie. one unconsidered during initial
development) to implement it and interact with the old framework (a bit
ambiguous, by 'framework' I mean 'the old code'). Allowing the system to be
forward compatible. As Andreas said, changing this interface breaks the rest
of the code because adding\removing a method invalidates their
implementation. This is ok during initial development when the interface is
new and being tested, but not when the interface has matured and many
classes are implementing it (and maybe even classes you have no control
over).

By providing such a contract *without* interfaces (ie, an abstract [or
other] base class) you are limiting the extensibility of the code. Saying
that though, if your set of code isn't a 'mixin' set of methods\properties.
Or you want to provide some base functionality then an abstract [or other]
base class may be more suitable, which is a design time decision. However
certain changes to such classes may *still* break classes that inherit them
so you do not avoid 'all this fuss' :)

n!
Nov 16 '05 #12
Hi Marius

----- Marius Horak wrote: ----
Andreas

"Andreas HÃ¥kansson" <andy.h (at) telia.com> wrote in messag
news:uW**************@TK2MSFTNGP12.phx.gbl..
Many of us spend our time helping people on this list, so there is n
need to be rude when someone asks you to clairify your question so
correct answer can be given


n! did not ask me to clarify my question. He/she just did not like it
I can bet that he/she does not do it everytime so his/her action (reaction
is selective

I'm sorry, but n! didn't give that impression to me. He was just pointing out that your question is too vague. I also think that your question is too vague

Why I asked the question
Well, I have to maintain an old system where most of objects are based o
interface
In one case I have to add a new parameter to one of the methods
This interface is used as base for 42 objects but the change is relevant t
one object only

Then your interface is not designed well. If a change to an interface is only good for one specific part of a program, and uesless for the rest, consider breaking up the interface in several smaller interfaces, each with a consistent logically grouped set of methods. As a guideline, your interface should not contain a lot of methods and each method should be logically consistent with the others

Without interface all would be simple as the method is referenced by th
object 7 times. With interface I face changing 411 lines adding useles
parameter or to create a separate object that will be 99% like other 4
objects

How would you solve this problem without interfaces

Having this experience I will never use interface in my code

Rather odd. Perhaps you are using interfaces where you shouldn't. Have you thought about that

M

Cheer
--
Tom Tempelaer

Nov 16 '05 #13
Very simple, if you don't like interfaces, rewrite the code.
If you don't like my responce, don't bother to use your brain and respond,
just press the delete button if is not too much effort.
If you are polite to people, then they will respond polite too.
Why I asked the question?
Well, I have to maintain an old system where most of objects are based on
interface.
In one case I have to add a new parameter to one of the methods.
This interface is used as base for 42 objects but the change is relevant to one object only.
Without interface all would be simple as the method is referenced by the
object 7 times. With interface I face changing 411 lines adding useless
parameter or to create a separate object that will be 99% like other 41
objects.
Having this experience I will never use interface in my code.


If you have to edit this many lines of code then that only means that the
original code is used in a "wrong" way to create interfaces and not in the
OOP way.
We are talking about a design fault here from the original programmer! He
simply did not understand enough about interfaces when he started creating
this.

The design of interfaces tells you that you have to duplicate the code and
assign a new ID to that interface to add the new function.
This is why you will find many documenst describing interfaces like this:
IMyInterface, IMyInterface2, IMyInterface3....
Interface does not contain code but maps external published functions to
inside published functions similar like dll entry points.

You are probably one of those designers that perfer to stick in a DOS
console way of programming, but the bad news is that DOS is getting outdated
fast.
You have a choice, evolve or get extinct.

For your information, the world is evolving to .NET so interfaces are also
old technology. Better to start learning the new stuff now. It takes a few
years to get to learn how to use it. Unless you want to sell DOS PC's.

Nov 16 '05 #14

<Ol**********@skyscan.be> skrev i meddelandet
news:40*********************@news.skynet.be...
Very simple, if you don't like interfaces, rewrite the code.
If you don't like my responce, don't bother to use your brain and respond,
just press the delete button if is not too much effort.
If you are polite to people, then they will respond polite too.
Why I asked the question?
Well, I have to maintain an old system where most of objects are based on interface.
In one case I have to add a new parameter to one of the methods.
This interface is used as base for 42 objects but the change is relevant to
one object only.
Without interface all would be simple as the method is referenced by the object 7 times. With interface I face changing 411 lines adding useless
parameter or to create a separate object that will be 99% like other 41
objects.
Having this experience I will never use interface in my code.


If you have to edit this many lines of code then that only means that the
original code is used in a "wrong" way to create interfaces and not in the
OOP way.
We are talking about a design fault here from the original programmer! He
simply did not understand enough about interfaces when he started creating
this.

The design of interfaces tells you that you have to duplicate the code and
assign a new ID to that interface to add the new function.
This is why you will find many documenst describing interfaces like this:
IMyInterface, IMyInterface2, IMyInterface3....
Interface does not contain code but maps external published functions to
inside published functions similar like dll entry points.

You are probably one of those designers that perfer to stick in a DOS
console way of programming, but the bad news is that DOS is getting

outdated fast.
You have a choice, evolve or get extinct.

For your information, the world is evolving to .NET so interfaces are also
old technology. Better to start learning the new stuff now. It takes a few
years to get to learn how to use it. Unless you want to sell DOS PC's.


This is were you loose me? .NET wont make interfaces obsolete since they
are an intrical part of any OOP based environement (like .NET). Perhaps
you ment to say ".NET is here to stay and interfaces are a part of it - time
to learn" ? =)

//Andreas
Nov 16 '05 #15
This seems to me to nail it.

You should not conclude that there's something inherently flawed about
interfaces from an example that misuses them.

"TT (Tom Tempelaere)" <_N_0SPA|/\|t*******@hotmail.com|/\|APS0_N_> wrote in
message news:AA**********************************@microsof t.com...

Why I asked the question?
Well, I have to maintain an old system where most of objects are based on interface.
In one case I have to add a new parameter to one of the methods.
This interface is used as base for 42 objects but the change is relevant to one object only.

Then your interface is not designed well. If a change to an interface is

only good for one specific part of a program, and uesless for the rest,
consider breaking up the interface in several smaller interfaces, each with
a consistent logically grouped set of methods. As a guideline, your
interface should not contain a lot of methods and each method should be
logically consistent with the others.
Nov 16 '05 #16
I see your point.

My background is Delphi (8 years) where polymorphism realy does not exist.
I went through the whole project, there are 86 objects based on interfaces.
Only one is based on two but none other object is based on those interfaces.
It means that basically all is pure inheritance.
Such style of programming I can only call 'programming for the sake of OOP
theory'.
Maybe one day I will find use for polymorphism in my systems.
So far I'm happy with simple inheritance.

MH
Nov 16 '05 #17

<Ol**********@skyscan.be> wrote in message
news:40*********************@news.skynet.be...
You are probably one of those designers that perfer to stick in a DOS
console way of programming, but the bad news is that DOS is getting outdated fast.
You have a choice, evolve or get extinct.


Olaf,

Do not worry about me, I have no financial needs to work.
I do what I do just not to get bored.
I can give up it today. Just my wife is earning so much (3 times what I get)
that she does not want to give up.

And I believe that if one cannot answer the question than one should keep
quiet.

MH
Nov 16 '05 #18
OK, fun is over.
Go back to work (I mean you, I'm going home, it's after 16:00).

MH
Nov 16 '05 #19
Marius,

Your question was as close to "What is the meaning of life" as
possible when talking programming ;) Adding context to it actually
makes it possible to reply to =)

//Andreas

"Marius Horak" <so*****@europe.eu> skrev i meddelandet
news:%2****************@tk2msftngp13.phx.gbl...

<Ol**********@skyscan.be> wrote in message
news:40*********************@news.skynet.be...
You are probably one of those designers that perfer to stick in a DOS
console way of programming, but the bad news is that DOS is getting outdated
fast.
You have a choice, evolve or get extinct.


Olaf,

Do not worry about me, I have no financial needs to work.
I do what I do just not to get bored.
I can give up it today. Just my wife is earning so much (3 times what I

get) that she does not want to give up.

And I believe that if one cannot answer the question than one should keep
quiet.

MH

Nov 16 '05 #20
"TT (Tom Tempelaere)" <_N_0SPA|/\|t*******@hotmail.com|/\|APS0_N_> wrote in
message news:AA**********************************@microsof t.com...
Then your interface is not designed well.
It's not my interface. Guys who wrote it had no OOP experience at all. They
bought a number of books and wrote the system.
Now they left and I have to fix it.
As a guideline, your interface should not contain a lot of methods and each method should be logically consistent with the others.

You mean 12 methods in an interface are too many?
What about 37?!!!
How would you solve this problem without interfaces?
Inheritance.

Having this experience I will never use interface in my code.

Rather odd. Perhaps you are using interfaces where you shouldn't. Have you

thought about that?

Of course. It's why we are having this fun. Never used, very unlikely I will
ever use.

MH

Nov 16 '05 #21

"Marius Horak" <so*****@europe.eu> wrote in message
news:eI**************@TK2MSFTNGP09.phx.gbl...
How would you solve this problem without interfaces?


Inheritance.


You'd have to be able to inherit from multiple abstract classes, which of
course you can't in C#, to accomplish the same thing.
Nov 16 '05 #22
Marius Horak wrote:
OK,
fun
The fun of asking a stupid question then, when someone replies blatantly
hinting, for _your_ own benefit, that you qualify your question, blast
him and everyone else too?

I wouldn't call that fun.
is over.
Bye!
Go back to work (I mean you, I'm going home, it's after 16:00).


Your attitude is awful.
Nov 16 '05 #23
"Marius Horak" <so*****@europe.eu> wrote in message
news:eI**************@TK2MSFTNGP09.phx.gbl...
"TT (Tom Tempelaere)" <_N_0SPA|/\|t*******@hotmail.com|/\|APS0_N_> wrote in message news:AA**********************************@microsof t.com...
Then your interface is not designed well.
It's not my interface. Guys who wrote it had no OOP experience at all.

They bought a number of books and wrote the system.
Now they left and I have to fix it.


Ok, I see.
As a guideline, your interface should not contain a lot of methods and

each method should be logically consistent with the others.

You mean 12 methods in an interface are too many?
What about 37?!!!


Ouch.
How would you solve this problem without interfaces?


Inheritance.


But what did you solve then? Your problem stays. You will have to refactor.

Cheers,
---
Tom Tempelaere
Nov 16 '05 #24
“Would you tell me, please, which way I ought to go?”
- "Alice"
“That depends a good deal on where you want to get to?”
- "Cheshire Cat"
“I don’t much care where.”
- "Alice"
“Then it doesn’t matter which way you go.”
- "Cheshire Cat"
from “Alice’s Adventures in Wonderland” by Lewis Carroll, Ch 6
"Marius Horak" <so*****@europe.eu> wrote in message
news:uD**************@TK2MSFTNGP11.phx.gbl...
As in subject.

Thanks

MH

Nov 16 '05 #25
DC
Marius Horak wrote:
I see your point.

My background is Delphi (8 years) I remember Turbo Pascal on Z80 CP/M machines.
Gee, I must be getting old<G>
where polymorphism realy does not exist.

That's nonsense.

LP,
Dejan
Nov 16 '05 #26
You know you really are the most obnoxious poster I've ever seen on this
newsgroup? Especially since I don't think you're actually trying to be a
troll!

Anyway, not long now, its quarter to five.

Andres

"Marius Horak" <so*****@europe.eu> wrote in message
news:uM*************@tk2msftngp13.phx.gbl...
OK, fun is over.
Go back to work (I mean you, I'm going home, it's after 16:00).

MH

Nov 16 '05 #27

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: matty | last post by:
Go away for a few days and you miss it all... A few opinions... Programming is a craft more than an art (software engineering, not black magic) and as such, is about writing code that works,...
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
12
by: Steve W. | last post by:
I just read the section (and did the exercise) in the C# Step by Step book that covers Explict Interface Implementation (where you specify in the method implementation the specific interface that...
3
by: Sai Kit Tong | last post by:
I posted for help on legacy code interface 2 days ago. Probably I didn't make it clear in my original mail. I got a couple of answers but none of them address my issues directly (See attached...
6
by: Michael Bray | last post by:
All, I was just reading over a new MSDN Magazine article by Juval Lowy on the new features in C# 2.0 (its a wonderful article, see link below.) In the section titled "Anonymous Method Example"...
7
by: farseer | last post by:
Here is the scenario: I have an interface which defines get methods for data that will make up a row in a table. However, the source of this data may, over time, switch/change (The company may...
24
by: Gaijinco | last post by:
I found one of that problems all of us have solve when they begin programming: given 3 numbers print the greater and the lesser one of the set. I was trying to remember the if-then-else...
63
by: John Salerno | last post by:
I know there's a request for a good IDE at least once a week on the ng, but hopefully this question is a little different. I'm looking for suggestions for a good cross-platform text editor (which...
159
by: bernard | last post by:
howdy! please recommend a good c compiler. - should be small - should be fast - should come with a good ide - should be inexpensive i am using windows os.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.