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