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

minimalistic real-world sample

hey all,
can someone please explain the advantages of interface-based programming?
And then tell me what this is opposed to?

thanks,
rodchar
Jun 12 '07 #1
6 1548
On 12 Jun, 14:31, rodchar <rodc...@discussions.microsoft.comwrote:
hey all,
can someone please explain the advantages of interface-based programming?
And then tell me what this is opposed to?

thanks,
rodchar
Hi,

Interface based programming is a concept where by the interactions
between components are defined by interfaces or "standards"; a bit
like a part of your code saying "if you want to talk to me then you
have to format the conversation in such and such a way". It's a bit
like the software equivalent of a hardware standard. Bluetooth, for
example, is a well defined standard, any component adhering to the
standard can communicate with any other component adhering to the
standard.

This type of programming is opposed to Object-Orientated Programming
or Aspect-Orientated Programming.

HTH,
Gary
http://www.garyshort.org

Jun 12 '07 #2
You would use interfaces when you want to abstract out a contract, as
opposed to using a concrete implementation of something.

A good example is the Stream class. Now, this isn't an interface, but
rather, an abstract class. For the most part, these things are the same in
concept, that they define a contract which must be implemented (in the case
of an abstract class, you have to derive from the class, burning your base
class).

With a Stream class, you have the concept of a stream, of reading bytes
in a forward manner, moving a pointer in the stream further along as you
read (this is in the case of reading, not in writing, but a similar concept
applies).

Now, with the Stream class being abstract, you could have any underlying
implementation, and there are, from compression streams, to file streams,
network streams, and the like. All of them do different things, but they
adhere to the model laid out by the abstract class.

The same thing applies for interfaces. IDisposable is a good example,
in that most classes have specific ways of disposing of resources, but they
all adhere to the model of how to dispose of those resources (through the
IDisposable interface).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:27**********************************@microsof t.com...
hey all,
can someone please explain the advantages of interface-based programming?
And then tell me what this is opposed to?

thanks,
rodchar
Jun 12 '07 #3
Thank you all for the information, this helps.

"rodchar" wrote:
hey all,
can someone please explain the advantages of interface-based programming?
And then tell me what this is opposed to?

thanks,
rodchar
Jun 13 '07 #4
still there?

hey all,
after a few more attempts I'm still having trouble diluting the concepts of
interfaces ( my apologies for the delay ).

My latest read is the following
http://www.samspublishing.com/articl...25857&seqNum=6

The article uses IEmployee as an example and after reading I still don't see
the reason or benefit. Could someone expand on the article just a little
more, please forgive my inexperience with this concept.

"rodchar" wrote:
hey all,
can someone please explain the advantages of interface-based programming?
And then tell me what this is opposed to?

thanks,
rodchar
Jul 3 '07 #5
I'll take this one :-)

Excluding spaghetti code there is procedural programming and OOP
programming. Procedural programming is a matter of calling "functionality"
passing along data needed by a function and typically getting back a
response from that function. The term OOP is often interpreted as
programming "to the class" i.e. if you need an Employee you instantiate an
employee object and then call methods Load, Save, etc. of that class. That
works better than procedural programming in a number of ways (perhaps)
primarily due to encapsulation which combines the data and the actions on
that data into one package.

It turns out however that it isn't the class or the object that is important
but rather what that object can do, i.e. the messages an object can respond
to. And that leads us to "program to the interface not to the class". Say
you need a collection of things that can sort. One thing you can do is add
a Sort method to a collection of Employees and then you can instantiate an
object of type Employees and tell it to Sort. The trouble is if you need to
pass this object to some other object that needed to display something as it
sorted (and I'm making up the example) it would have to take a parameter of
EmployeeCollection which is a pretty unique class. If instead this other
object was designed to accept classes that implement ISortable it could
accept a collection of Employees but also any collection which is capable of
responding to ISortable messages. ISortable.Key for instance might return a
sort key. That your employees collection implemented the ISortable
interface would be all that is needed to know for a fact that ISortable Key
would return the proper sort key. There is no need to create a special
class to recognize Employees.

Imagine now you want to create a whole bunch of classes that can "draw". If
you create an IDrawable interface you can pass "any" object to a rendering
object and that object could check if the object passed implements
IDrawable. If it does then it can safely call the .Draw() method, if it
doesn't it will not try to draw it. An Employee object (for instance)
wouldn't likely implement IDrawable so while it is silly to send it to the
renderer nothing bad happens if you do.

Did that help?

Tom
"rodchar" <ro*****@discussions.microsoft.comwrote...
still there?

hey all,
after a few more attempts I'm still having trouble diluting the concepts
of
interfaces ( my apologies for the delay ).

My latest read is the following
http://www.samspublishing.com/articl...25857&seqNum=6

The article uses IEmployee as an example and after reading I still don't
see
the reason or benefit. Could someone expand on the article just a little
more, please forgive my inexperience with this concept.

"rodchar" wrote:
>hey all,
can someone please explain the advantages of interface-based programming?
And then tell me what this is opposed to?

thanks,
rodchar

Jul 4 '07 #6
Thanks for your thoroughness, may i please ask these follow-up questions...
object of type Employees and tell it to Sort. The trouble is if you need to
pass this object to some other object that needed to display something as it
sorted (and I'm making up the example) it would have to take a parameter of
I'm not sure I understand what the trouble is yet... when you said "to
display something as it sorted..", is this a multi-thread issue?
EmployeeCollection which is a pretty unique class. If instead this other
object was designed to accept classes that implement ISortable it could
accept a collection of Employees but also any collection which is capable of
responding to ISortable messages.


"Tom Leylan" wrote:
I'll take this one :-)

Excluding spaghetti code there is procedural programming and OOP
programming. Procedural programming is a matter of calling "functionality"
passing along data needed by a function and typically getting back a
response from that function. The term OOP is often interpreted as
programming "to the class" i.e. if you need an Employee you instantiate an
employee object and then call methods Load, Save, etc. of that class. That
works better than procedural programming in a number of ways (perhaps)
primarily due to encapsulation which combines the data and the actions on
that data into one package.

It turns out however that it isn't the class or the object that is important
but rather what that object can do, i.e. the messages an object can respond
to. And that leads us to "program to the interface not to the class". Say
you need a collection of things that can sort. One thing you can do is add
a Sort method to a collection of Employees and then you can instantiate an
object of type Employees and tell it to Sort. The trouble is if you need to
pass this object to some other object that needed to display something as it
sorted (and I'm making up the example) it would have to take a parameter of
EmployeeCollection which is a pretty unique class. If instead this other
object was designed to accept classes that implement ISortable it could
accept a collection of Employees but also any collection which is capable of
responding to ISortable messages. ISortable.Key for instance might return a
sort key. That your employees collection implemented the ISortable
interface would be all that is needed to know for a fact that ISortable Key
would return the proper sort key. There is no need to create a special
class to recognize Employees.

Imagine now you want to create a whole bunch of classes that can "draw". If
you create an IDrawable interface you can pass "any" object to a rendering
object and that object could check if the object passed implements
IDrawable. If it does then it can safely call the .Draw() method, if it
doesn't it will not try to draw it. An Employee object (for instance)
wouldn't likely implement IDrawable so while it is silly to send it to the
renderer nothing bad happens if you do.

Did that help?

Tom
"rodchar" <ro*****@discussions.microsoft.comwrote...
still there?

hey all,
after a few more attempts I'm still having trouble diluting the concepts
of
interfaces ( my apologies for the delay ).

My latest read is the following
http://www.samspublishing.com/articl...25857&seqNum=6

The article uses IEmployee as an example and after reading I still don't
see
the reason or benefit. Could someone expand on the article just a little
more, please forgive my inexperience with this concept.

"rodchar" wrote:
hey all,
can someone please explain the advantages of interface-based programming?
And then tell me what this is opposed to?

thanks,
rodchar


Jul 6 '07 #7

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

Similar topics

18
by: Ken | last post by:
Hi. Can anyone refer me to any articles about the compatibility between c++ polymorphism and real-time programming? I'm currently on a real-time c++ project, and we're having a discussion...
4
by: Aaron W. West | last post by:
Timings... sometimes there are almost too many ways to do the same thing. The only significant findings I see from all the below timings is: 1) Integer math is generally fastest, naturally....
4
by: Allan Adler | last post by:
I'm trying to reinstall RedHat 7.1 Linux on a PC that was disabled when I tried to upgrade from RH7.1 to RH9. This is presenting lots of unexpected difficulties. Apart from wanting to keep the old...
10
by: Pavils Jurjans | last post by:
Hallo, It is know issue that due to the fact that computer has to store the real numbers in limited set of bytes, thus causing a minor imprecision from the decimal value that likely was stored....
17
by: David Scemama | last post by:
Hi, I'm writing a program using VB.NET that needs to communicate with a DOS Pascal program than cannot be modified. The communication channel is through some file databases, and I have a huge...
16
by: DirtyHarry | last post by:
Good day everyone. This sounds like a stupid question, but I became just curious yesterday, and I looked up several textbooks. However, no textbooks on computer language (that I have ) mentioned...
9
by: Michael Sparks | last post by:
Hi, I'm interested in writing a simple, minimalistic, non persistent (at this stage) software transactional memory (STM) module. The idea being it should be possible to write such a beast in a...
0
by: Johannes Nix | last post by:
Hi, this might be of interest for people who are look for practical information on doing real-time signal processing, possibly using multiple CPUs, and wonder whether it's possible to use...
2
by: Blubaugh, David A. | last post by:
To All, I have done some additional research into the possibility of utilizing Python for hard real time development. I have seen on various websites where this has been discussed before on...
3
by: Kurt Mueller | last post by:
David, Am 07.10.2008 um 01:25 schrieb Blubaugh, David A.: As others mentioned before, python is not the right tool for "HARD REAL TIME". But: Maybe you can isolate the part of your...
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: 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
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: 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
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
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.