473,324 Members | 2,456 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,324 software developers and data experts.

passage in a book

hi,

i was reading a vb.net book that said the following regarding:

Interfaces allow you to program using methods on the interface rather than
methods on the object?

How is this a benefit in lamen's terms?

thanks,
mj
Nov 21 '05 #1
10 1366
It basically means that it allows you to look at the object in terms of its
interface - and thus be guaranteed that it has a particular method.

So let's say you have classes A, B, C. You will have a collection of
objects, and each object in the collection will be an instance of one of
those. You can either:
a) Look at each object in the collection, figure out if it's an A, B or C.
Then cast it to the right type, and call method DoSomething on it
b) Make each class implement ISomeInterface which has a method DoSomething.
Then just cast each object to an ISomeInterface and call DoSomething.

Which is easier?

Consider down the road, you add a class D. Scenario 'a', you would have to
change the code for your collection to now deal with a class D. Scenario
'b', you don't need to do anything, as long as class D implements
ISomeInterface.

"mattie" <ma****@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
hi,

i was reading a vb.net book that said the following regarding:

Interfaces allow you to program using methods on the interface rather than
methods on the object?

How is this a benefit in lamen's terms?

thanks,
mj

Nov 21 '05 #2
It basically means that it allows you to look at the object in terms of its
interface - and thus be guaranteed that it has a particular method.

So let's say you have classes A, B, C. You will have a collection of
objects, and each object in the collection will be an instance of one of
those. You can either:
a) Look at each object in the collection, figure out if it's an A, B or C.
Then cast it to the right type, and call method DoSomething on it
b) Make each class implement ISomeInterface which has a method DoSomething.
Then just cast each object to an ISomeInterface and call DoSomething.

Which is easier?

Consider down the road, you add a class D. Scenario 'a', you would have to
change the code for your collection to now deal with a class D. Scenario
'b', you don't need to do anything, as long as class D implements
ISomeInterface.

"mattie" <ma****@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
hi,

i was reading a vb.net book that said the following regarding:

Interfaces allow you to program using methods on the interface rather than
methods on the object?

How is this a benefit in lamen's terms?

thanks,
mj

Nov 21 '05 #3
thanks for the explanation. what do you mean when you said:

Then just cast each object to an ISomeInterface and call DoSomething.

how would the syntax look for that line?

mj

"Marina" wrote:
It basically means that it allows you to look at the object in terms of its
interface - and thus be guaranteed that it has a particular method.

So let's say you have classes A, B, C. You will have a collection of
objects, and each object in the collection will be an instance of one of
those. You can either:
a) Look at each object in the collection, figure out if it's an A, B or C.
Then cast it to the right type, and call method DoSomething on it
b) Make each class implement ISomeInterface which has a method DoSomething.
Then just cast each object to an ISomeInterface and call DoSomething.

Which is easier?

Consider down the road, you add a class D. Scenario 'a', you would have to
change the code for your collection to now deal with a class D. Scenario
'b', you don't need to do anything, as long as class D implements
ISomeInterface.

"mattie" <ma****@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
hi,

i was reading a vb.net book that said the following regarding:

Interfaces allow you to program using methods on the interface rather than
methods on the object?

How is this a benefit in lamen's terms?

thanks,
mj


Nov 21 '05 #4
thanks for the explanation. what do you mean when you said:

Then just cast each object to an ISomeInterface and call DoSomething.

how would the syntax look for that line?

mj

"Marina" wrote:
It basically means that it allows you to look at the object in terms of its
interface - and thus be guaranteed that it has a particular method.

So let's say you have classes A, B, C. You will have a collection of
objects, and each object in the collection will be an instance of one of
those. You can either:
a) Look at each object in the collection, figure out if it's an A, B or C.
Then cast it to the right type, and call method DoSomething on it
b) Make each class implement ISomeInterface which has a method DoSomething.
Then just cast each object to an ISomeInterface and call DoSomething.

Which is easier?

Consider down the road, you add a class D. Scenario 'a', you would have to
change the code for your collection to now deal with a class D. Scenario
'b', you don't need to do anything, as long as class D implements
ISomeInterface.

"mattie" <ma****@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
hi,

i was reading a vb.net book that said the following regarding:

Interfaces allow you to program using methods on the interface rather than
methods on the object?

How is this a benefit in lamen's terms?

thanks,
mj


Nov 21 '05 #5
(ISomeInterface)myObj where myObj is some object that you have that
implements this interface. Otherwise, this code would throw an exception.

"mattie" <ma****@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
thanks for the explanation. what do you mean when you said:

Then just cast each object to an ISomeInterface and call DoSomething.

how would the syntax look for that line?

mj

"Marina" wrote:
It basically means that it allows you to look at the object in terms of
its
interface - and thus be guaranteed that it has a particular method.

So let's say you have classes A, B, C. You will have a collection of
objects, and each object in the collection will be an instance of one of
those. You can either:
a) Look at each object in the collection, figure out if it's an A, B or
C.
Then cast it to the right type, and call method DoSomething on it
b) Make each class implement ISomeInterface which has a method
DoSomething.
Then just cast each object to an ISomeInterface and call DoSomething.

Which is easier?

Consider down the road, you add a class D. Scenario 'a', you would have
to
change the code for your collection to now deal with a class D.
Scenario
'b', you don't need to do anything, as long as class D implements
ISomeInterface.

"mattie" <ma****@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
> hi,
>
> i was reading a vb.net book that said the following regarding:
>
> Interfaces allow you to program using methods on the interface rather
> than
> methods on the object?
>
> How is this a benefit in lamen's terms?
>
> thanks,
> mj


Nov 21 '05 #6
(ISomeInterface)myObj where myObj is some object that you have that
implements this interface. Otherwise, this code would throw an exception.

"mattie" <ma****@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
thanks for the explanation. what do you mean when you said:

Then just cast each object to an ISomeInterface and call DoSomething.

how would the syntax look for that line?

mj

"Marina" wrote:
It basically means that it allows you to look at the object in terms of
its
interface - and thus be guaranteed that it has a particular method.

So let's say you have classes A, B, C. You will have a collection of
objects, and each object in the collection will be an instance of one of
those. You can either:
a) Look at each object in the collection, figure out if it's an A, B or
C.
Then cast it to the right type, and call method DoSomething on it
b) Make each class implement ISomeInterface which has a method
DoSomething.
Then just cast each object to an ISomeInterface and call DoSomething.

Which is easier?

Consider down the road, you add a class D. Scenario 'a', you would have
to
change the code for your collection to now deal with a class D.
Scenario
'b', you don't need to do anything, as long as class D implements
ISomeInterface.

"mattie" <ma****@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
> hi,
>
> i was reading a vb.net book that said the following regarding:
>
> Interfaces allow you to program using methods on the interface rather
> than
> methods on the object?
>
> How is this a benefit in lamen's terms?
>
> thanks,
> mj


Nov 21 '05 #7
Or, perhaps more relevantly to ...dotnet.languages.*vb* :

DirectCast( myObj, ISomeInterface )

unless you know something we don't ... ;-)

Regards,
Phill W.

"Marina" <so*****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
(ISomeInterface)myObj where myObj is some object that you have that
implements this interface. Otherwise, this code would throw an exception.

"mattie" <ma****@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
thanks for the explanation. what do you mean when you said:

Then just cast each object to an ISomeInterface and call DoSomething.

how would the syntax look for that line?

Nov 21 '05 #8
Or, perhaps more relevantly to ...dotnet.languages.*vb* :

DirectCast( myObj, ISomeInterface )

unless you know something we don't ... ;-)

Regards,
Phill W.

"Marina" <so*****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
(ISomeInterface)myObj where myObj is some object that you have that
implements this interface. Otherwise, this code would throw an exception.

"mattie" <ma****@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
thanks for the explanation. what do you mean when you said:

Then just cast each object to an ISomeInterface and call DoSomething.

how would the syntax look for that line?

Nov 21 '05 #9
Thank you very much. this helped a lot.

"Phill. W" wrote:
Or, perhaps more relevantly to ...dotnet.languages.*vb* :

DirectCast( myObj, ISomeInterface )

unless you know something we don't ... ;-)

Regards,
Phill W.

"Marina" <so*****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
(ISomeInterface)myObj where myObj is some object that you have that
implements this interface. Otherwise, this code would throw an exception.

"mattie" <ma****@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
thanks for the explanation. what do you mean when you said:

Then just cast each object to an ISomeInterface and call DoSomething.

how would the syntax look for that line?


Nov 21 '05 #10
Would this be along the same lines as APIs?

"Marina" wrote:
It basically means that it allows you to look at the object in terms of its
interface - and thus be guaranteed that it has a particular method.

So let's say you have classes A, B, C. You will have a collection of
objects, and each object in the collection will be an instance of one of
those. You can either:
a) Look at each object in the collection, figure out if it's an A, B or C.
Then cast it to the right type, and call method DoSomething on it
b) Make each class implement ISomeInterface which has a method DoSomething.
Then just cast each object to an ISomeInterface and call DoSomething.

Which is easier?

Consider down the road, you add a class D. Scenario 'a', you would have to
change the code for your collection to now deal with a class D. Scenario
'b', you don't need to do anything, as long as class D implements
ISomeInterface.

"mattie" <ma****@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
hi,

i was reading a vb.net book that said the following regarding:

Interfaces allow you to program using methods on the interface rather than
methods on the object?

How is this a benefit in lamen's terms?

thanks,
mj


Nov 21 '05 #11

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

Similar topics

1
by: sysindex | last post by:
I need to write an algorithm to retrieve most relevant passage from a large body of text. The passage needs to relevant to the search term. Sort of like what Google displays on their search results...
12
by: Guido Mureddu | last post by:
Hello, I'm a student in electronic engineering. I do know you've seen and answered this sort of topic/request countless times, but I haven't found past threads as helpful as I had hoped, and...
16
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
0
by: mattie | last post by:
hi, i was reading a vb.net book that said the following regarding: Interfaces allow you to program using methods on the interface rather than methods on the object? How is this a benefit in...
11
by: www.douglassdavis.com | last post by:
I'm looking for advice here, and I would really appreciate it if you could help. Is there a VB 2005 book that you like and would recommend (and why)? Would you consider it good for...
263
by: Malcolm McLean | last post by:
The webpages for my new book are now up and running. The book, Basic Algorithms, describes many of the fundamental algorithms used in practical programming, with a bias towards graphics. It...
6
by: Hello | last post by:
Hello every body Please can any body tells me a good book that can teach me "visual basic 2005" (as beginner). Thank you all =========================================
1
by: jrw133 | last post by:
i got this program the other day and ive just started it and i am getting some errors that i cant figure out. requirements: 1)create a clas called Book. a Book has three data members: m_title,...
76
by: lorlarz | last post by:
Crockford's JavaScript, The Good Parts (a book review). This shall perhaps be the world's shortest book review (for one of the world's shortests books). I like Douglas Crockford (because I am a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.