473,396 Members | 1,963 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,396 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 1369
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...
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
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
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.