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

Interfaces used always with new classes, why?

Hi,

As a convention we always create interfaces before creating classes for
class libraries.

we then implement this interface in a class.

Can someone point out the reasons\advantages for doing this in a simple way.

Thanks
Kiran
Feb 10 '06 #1
9 1183
Not sure I understand your question. Who is "we" because I have not heard
of that being a convention? Some people may not know they need an interface
until they created some classes and observed the similar methods being
created. Other do just what you do because they recognize the need for a
interface and just want to define it so that class is forced to implement it
immediately.
"Kiran" <so*****@somewhere.com> wrote in message
news:eI**************@TK2MSFTNGP12.phx.gbl...
Hi,

As a convention we always create interfaces before creating classes for
class libraries.

we then implement this interface in a class.

Can someone point out the reasons\advantages for doing this in a simple
way.

Thanks
Kiran

Feb 10 '06 #2
Kiran wrote:
Hi,

As a convention we always create interfaces before creating classes for
class libraries.

we then implement this interface in a class.

Can someone point out the reasons\advantages for doing this in a simple
way.

Say you want to input a Day and get back the temperature for that Day.

But you want it to be global, so some use Fahrenheit, some Celsius.
The inteface is the same,

int temp(DateTime day)
But the calculations behind the method are different and it returns
different values.



Thanks
Kiran

Feb 10 '06 #3
Peter Rilling wrote:
Not sure I understand your question. Who is "we" because I have not heard
of that being a convention? Some people may not know they need an interface
until they created some classes and observed the similar methods being
created. Other do just what you do because they recognize the need for a
interface and just want to define it so that class is forced to implement it
immediately.
"Kiran" <so*****@somewhere.com> wrote in message
news:eI**************@TK2MSFTNGP12.phx.gbl...
Hi,

As a convention we always create interfaces before creating classes for
class libraries.

we then implement this interface in a class.

Can someone point out the reasons\advantages for doing this in a simple
way.

Thanks
Kiran


Hi Peter,

we do it that way in our project, are there any performance\security
issue in this

Thanks
Kiran
Feb 11 '06 #4
John Bailo wrote:
Kiran wrote:
Hi,

As a convention we always create interfaces before creating classes
for class libraries.

we then implement this interface in a class.

Can someone point out the reasons\advantages for doing this in a
simple way.


Say you want to input a Day and get back the temperature for that Day.

But you want it to be global, so some use Fahrenheit, some Celsius.
The inteface is the same,

int temp(DateTime day)
But the calculations behind the method are different and it returns
different values.



Thanks
Kiran

Hi John,

so it's a reusability thing, is performance\security related to this

Thanks
Kiran
Feb 11 '06 #5
There are no security or performance issues related to just defining
interfaces before the class.

Security and performance come from the design of the overall code base, not
on the order that things get implemented.

"Kiran" <so*****@somewhere.com> wrote in message
news:%2***************@TK2MSFTNGP14.phx.gbl...
John Bailo wrote:
Kiran wrote:
Hi,

As a convention we always create interfaces before creating classes for
class libraries.

we then implement this interface in a class.

Can someone point out the reasons\advantages for doing this in a simple
way.


Say you want to input a Day and get back the temperature for that Day.

But you want it to be global, so some use Fahrenheit, some Celsius.
The inteface is the same,

int temp(DateTime day)
But the calculations behind the method are different and it returns
different values.



Thanks
Kiran

Hi John,

so it's a reusability thing, is performance\security related to this

Thanks
Kiran

Feb 11 '06 #6
Peter Rilling wrote:
There are no security or performance issues related to just defining
interfaces before the class.

Security and performance come from the design of the overall code base, not
on the order that things get implemented.

"Kiran" <so*****@somewhere.com> wrote in message
news:%2***************@TK2MSFTNGP14.phx.gbl...
John Bailo wrote:
Kiran wrote:
Hi,

As a convention we always create interfaces before creating classes for
class libraries.

we then implement this interface in a class.

Can someone point out the reasons\advantages for doing this in a simple
way.

Say you want to input a Day and get back the temperature for that Day.

But you want it to be global, so some use Fahrenheit, some Celsius.
The inteface is the same,

int temp(DateTime day)
But the calculations behind the method are different and it returns
different values.


Thanks
Kiran


Hi John,

so it's a reusability thing, is performance\security related to this

Thanks
Kiran


Thanks John
Feb 11 '06 #7
Peter Rilling wrote:
There are no security or performance issues related to just defining
interfaces before the class.

Security and performance come from the design of the overall code base, not
on the order that things get implemented.

"Kiran" <so*****@somewhere.com> wrote in message
news:%2***************@TK2MSFTNGP14.phx.gbl...
John Bailo wrote:
Kiran wrote:
Hi,

As a convention we always create interfaces before creating classes for
class libraries.

we then implement this interface in a class.

Can someone point out the reasons\advantages for doing this in a simple
way.

Say you want to input a Day and get back the temperature for that Day.

But you want it to be global, so some use Fahrenheit, some Celsius.
The inteface is the same,

int temp(DateTime day)
But the calculations behind the method are different and it returns
different values.


Thanks
Kiran


Hi John,

so it's a reusability thing, is performance\security related to this

Thanks
Kiran


Thanks Peter
Feb 11 '06 #8

Or you may want one collection class to be able to operate on particular
members across similar classes that require a certain operation.
Implementing the same interface to those classes will make this very
possible, as the collection members are defined relative to that interface.

Maybe you have a method that does a desired operation on data members (sorry
for redefining a method ), again across classes (maybe similar or can even
be different), such a method that takes an interface as an parameter will
make this very possible as that interface will be implemented to those
classes. Containing the relevant members to be implemented

Not really convention, as for reason, could be the above, I worked for one
place where the architects bestowed interfaces to the coders that had to
implement before coding the class bodies, why? I guess as well as extreme
programming we also have totalitarian programming. But everyone was happy in
the end, documentation was also allot easier.

- SpotNet

"John Bailo" <ja*****@texeme.com> wrote in message
news:43**************@texeme.com...
: Kiran wrote:
: > Hi,
: >
: > As a convention we always create interfaces before creating classes for
: > class libraries.
: >
: > we then implement this interface in a class.
: >
: > Can someone point out the reasons\advantages for doing this in a simple
: > way.
:
:
: Say you want to input a Day and get back the temperature for that Day.
:
: But you want it to be global, so some use Fahrenheit, some Celsius.
:
:
: The inteface is the same,
:
: int temp(DateTime day)
:
:
: But the calculations behind the method are different and it returns
: different values.
:
:
:
:
:
: >
: > Thanks
: > Kiran
Feb 12 '06 #9
Kiran wrote:
As a convention we always create interfaces before creating classes
for class libraries.

we then implement this interface in a class.

Can someone point out the reasons\advantages for doing this in a
simple way.

Well, you should not do this for *every* class, it is unneccessary. If
yoiur coding guidelines are to do that then it indicates that the person
who wrote the guidelines either did not understand OO principles or was
too lazy to do a proper OO design. Interface programming is extremely
powerful when used correctly.
Say you want to input a Day and get back the temperature for that
Day. But you want it to be global, so some use Fahrenheit, some
Celsius.

The inteface is the same,

int temp(DateTime day)


Well, I don't think that this is a good example, the 'interface' is the
same, but the behaviour is not. The problem is that the return value
from the method must be interpretted in different ways depending on
whether it returns C or F. Interface programming is all about
*behaviours*, that is, you don't care how the code performs the action,
all you care about is what it does.

A better example is an interface that tells a shape to render itself (ie
draw itself).

in code:

interface IRender
{
void RenderMe(Graphics g);
}

Any object with a visual interface can render itself. The object knows
how toi draw itself. The caller does not care how this is performed, or
what the shape is like, all it cares aout is the behaviour that the
shape will draw itself in the Graphics context.

class Square : IRender
{
// other code
public void RenderMe(Graphics g){/*code here*/}
}

class Circle : IRender
{
// other code
public void RenderMe(Graphics g){/*code here*/}
}

class Window : Form
{
List<IRender> shapes;
public Init()
{
// fill the shapes collection with Circles and Squares
}
public override void Paint(PaintEventArgs e)
{
foreach(IRender render in shapes)
{
// This code does not care if the shape is a Circle or a
Square
// all it cares is that it can draw itself
render->RenderMe(e.Graphics);
}
base.Paint(e);
}
}

Richard
--
Free .NET tutorials,
Fusion: http://www.grimes.demon.co.uk/workshops/fusionWS.htm
Security: http://www.grimes.demon.co.uk/workshops/securityWS.htm
Feb 14 '06 #10

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

Similar topics

21
by: Franco Gustavo | last post by:
Hi, Please help me to understand this, because I don't see what I'm missing. I was reading a lot of examples on Internet that explain that C# doesn't implement multiple inheritance it...
8
by: Phil D | last post by:
Hi, I am new to c# and oop and have a question about interfaces which I hope someone can help me with. The book I am using (C# Step by Step) explains how to create and implement interfaces...
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
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...
23
by: Dave Rahardja | last post by:
Since C++ is missing the "interface" concept present in Java, I've been using the following pattern to simulate its behavior: class Interface0 { public: virtual void fn0() = 0; };
5
by: raylopez99 | last post by:
I understand delegates (static and non-static) and I agree they are very useful, and that the "Forms" used in the Windows .NET API could not work without them. That said, I'm curious as to how...
4
by: Peter | last post by:
Hi I was wondering about the use of interfaces for "data classes". Actually I don't know the accepted term for these types of classes - they are simply classes which have getters and setters, to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.