473,387 Members | 1,423 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,387 software developers and data experts.

Interfaces ic C#

Allow me to ask a really stupid question.
Why use interfaces in C# and .NET if you're not dealing
with hereditary COM+ components / clients.
I can see no benefit from it. Only complicates things.
Doesn't add code security. You still must get hold of
the .dll for the interface implementing class. They talk
of it as a 'Contract' and say that the implementing class
must implement the specific code. But contracts can be
broken - what if the class implements other public
methods? Nothing prevents you from doing that.
Nov 15 '05 #1
2 2043
Just an example!
-----------------------------------------------------------
using System;

namespace XmlWinApp.IBusiness
{
public interface IContract
{
void NiceMethod();
}
}
-----------------------------------------------------------
using System;
using System.IO;

namespace XmlWinApp.Business
{
public class IContractImplement
{
public IContractImplement()
{
}
public void NiceMethod()
{
// I'm a nice guy adhearing to the
contract.
}
public void NastyMethod()
{
// I'm not
FileStream fs = new FileStream
("IDontExist", FileMode.Open);
}
}
}
-----Original Message-----
Allow me to ask a really stupid question.
Why use interfaces in C# and .NET if you're not dealing
with hereditary COM+ components / clients.
I can see no benefit from it. Only complicates things.
Doesn't add code security. You still must get hold of
the .dll for the interface implementing class. They talk
of it as a 'Contract' and say that the implementing class
must implement the specific code. But contracts can be
broken - what if the class implements other public
methods? Nothing prevents you from doing that.
.

Nov 15 '05 #2
> methods? Nothing prevents you from doing that.

But it guarantees that the members defined in the interface will be members
of any derived class.

This is how you can write a method that accepts an IDataReader parameter and
it will work with both an OleDbDataReader and an SqlDataReader (or any other
class that derives from IDataReader).

The contract only says that if the interface defines it, the derived class
must also include it. It does not say that if the interface does not include
then the derived class cannot include it.

Josh
"Folke" <fo*********@se.unisys.com> wrote in message
news:11****************************@phx.gbl...
Allow me to ask a really stupid question.
Why use interfaces in C# and .NET if you're not dealing
with hereditary COM+ components / clients.
I can see no benefit from it. Only complicates things.
Doesn't add code security. You still must get hold of
the .dll for the interface implementing class. They talk
of it as a 'Contract' and say that the implementing class
must implement the specific code. But contracts can be
broken - what if the class implements other public
methods? Nothing prevents you from doing that.

Nov 15 '05 #3

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

Similar topics

1
by: baylor | last post by:
In C#, an interface cannot mark any method as static. i'm told the ILASM supports it but i've never tested that Two questions. First, why? OK, i've heard the reason about interfaces being...
30
by: Frank Rizzo | last post by:
We are having one of those religious debates at work: Interfaces vs Classes. My take is that Classes give you more flexibility. You can enforce a contract on the descendant classes by marking...
8
by: John | last post by:
What is the purpose / benefit of using an interface statement? It doesn't seem like anything more than a different way to make a class... (except you can't define any procedures in an interface...
9
by: Sean Kirkpatrick | last post by:
To my eye, there doesn't seem to be a whole lot of difference between the two of them from a functional point of view. Can someone give me a good explanation of why one vs the other? Sean
18
by: _dee | last post by:
Question about best use of interfaces: Say there's a 'Master' class that needs to implement a few interfaces: class Master : I1, I2, I3 { } The actual code already exists in smaller...
22
by: RSH | last post by:
Hi, I have been reading on interfaces working on samples I've run across on the web. For the life of me I cannot seem to grasp them. It appears to me that interfaces are simply blueprints to...
18
by: Tony | last post by:
class Interface { public: virtual void DoItNow()=0; }; class A: public Interface { public: void DoItNow(); // satisfies interface explicitly
5
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, I am actually a VB.Net guy, but I have worked somewhat with C++ and C#. I just want to ask about the relationship between Abstract Classes and Interfaces. My first question is if...
10
by: hyperboreean | last post by:
Hi, Probably it has been asked before, but I'll still ask. Why doesn't python provide interfaces trough its standard library? Or it was ever proposed to be included in the language? Zope's...
23
by: A.Gallus | last post by:
If I declare a function pure virtual: class A { virtual void myfunc() = 0; } and I derive a class from A: class B : public A
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.