书中的一段 [英] passage in a book
本文介绍了书中的一段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i正在阅读一本关于以下内容的vb.net书:
接口允许你使用方法编程对象上的界面而不是
方法?
这对lamen的条款有什么好处?
谢谢,
mj
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
推荐答案
它基本上意味着它允许你以对象的方式来看待对象它的
界面 - 因此可以保证它有一个特定的方法。
所以让我们说你有A,B,C类。将有一个
对象的集合,集合中的每个对象将是
之一的实例。您可以:
a)查看集合中的每个对象,确定它是A,B还是C.
然后将其转换为正确的类型,并调用方法DoSomething上面
b)让每个类实现ISomeInterface,它有一个方法DoSomething。
然后只需将每个对象转换为ISomeInterface并调用DoSomething。
哪个更容易?
考虑一下,你要添加一个D类。场景''a'',你必须
更改您的集合的代码,现在处理D类。场景
''b'',您不需要做任何事情,只要D类实现
ISomeInterface。
" mattie" <毫安**** @ discussions.microsoft.com>在留言中写道
新闻:3A ********************************** @ microsof t.com ...
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...
我正在阅读一本关于以下内容的vb.net书:
接口允许你程序在界面上使用方法而不是对象上的方法?
如何在lamen的条款中获益?
谢谢,> mj
它基本上意味着它允许您根据其
界面查看对象 - 因此保证它有一个特定的方法。
所以,假设你有A,B,C类。你将有一个
对象的集合,集合中的每个对象都是
之一的实例。您可以:
a)查看集合中的每个对象,确定它是A,B还是C.
然后将其转换为正确的类型,并调用方法DoSomething上面
b)让每个类实现ISomeInterface,它有一个方法DoSomething。
然后只需将每个对象转换为ISomeInterface并调用DoSomething。
哪个更容易?
考虑一下,你要添加一个D类。场景''a'',你必须
更改您的集合的代码,现在处理D类。场景
''b'',您不需要做任何事情,只要D类实现
ISomeInterface。
" mattie" <毫安**** @ discussions.microsoft.com>在留言中写道
新闻:3A ********************************** @ microsof t.com ...
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...
我正在阅读一本关于以下内容的vb.net书:
接口允许你程序在界面上使用方法而不是对象上的方法?
如何在lamen的条款中获益?
谢谢,> mj
感谢您的解释。你说的是什么意思:
然后将每个对象转换为ISomeInterface并调用DoSomething。
语法如何查找那条线?
mj
" Marina"写道:
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:
它基本上意味着它允许您根据其界面查看对象 - 因此可以保证它具有特定的方法。
所以,假设您有A,B,C类。您将拥有一组
对象,并且该集合中的每个对象都将是其中一个对象的实例。 。您可以:
a)查看集合中的每个对象,确定它是A,B还是C.
然后将其转换为正确的类型,并调用方法DoSomething
b)让每个类实现ISomeInterface,它有一个DoSomething方法。
然后将每个对象转换为一个ISomeInterface并调用DoSomething。
哪个更容易?
<考虑下来,你要添加一个D类。场景''a'',你将不得不改变你的收藏代码,现在处理D类。情景
'' b'',你不需要做任何事情,只要D级实现了ISomeInterface。
mattie <毫安**** @ discussions.microsoft.com>在消息中写道
新闻:3A ********************************** @ microsof t.com。 ..
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...
我正在读一本关于以下内容的vb.net书:
接口允许你使用方法编程对象的界面而不是
方法?
这对lamen的术语有什么好处?
谢谢,
mj
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
这篇关于书中的一段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文