接口与虚拟方法 [英] Interface vs. Virtual methods

查看:67
本文介绍了接口与虚拟方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,


这两种不同方法的优点和缺点是什么?


1。我使用一些虚拟方法创建一个基类,然后从这个类派生我的

类,重写这些方法并使用这个类。


2。我使用接口。


什么是更快的.NET?我认为派生自基类。


主要目的是创建一些第二级的类,其中

方法名称与Initialize相同( ),Update(),Get(),Sage()。添加()等


谢谢,

Dmitri

All,

What are advantages and disadvantages of these two different approaches?

1 . I create a base class with a few virtual methods, then I derive my
classes from this class, override these methods and use this class.

2. I work with interfaces.

What is faster in .NET? I supposed that deriving from the base classes.

The main purpose was to create a few classes of the second level having the
same method names like Initialize(), Update(), Get(), Sage(). Add() etc.

Thanks,
Dmitri

推荐答案




使用虚方法会导致内部创建vtable。我不认为使用接口会导致这种情况,因为我们没有覆盖任何东西。那么界面会更快吗?

-

Rakesh Rajan

" Just D"写道:
Hi,

Using virtual methods would result in the creation of vtable internally. I don''t think using interfaces would result in that, since we are not overriding anything. So woulnd''t interfaces be faster?
--
Rakesh Rajan
"Just D" wrote:
全部,

这两种不同方法的优点和缺点是什么?

1。我使用一些虚拟方法创建一个基类,然后从这个类派生我的
类,重写这些方法并使用这个类。

2.我使用接口。

.NET的速度更快?我认为派生自基类。

主要目的是创建一些具有相同方法名称的第二级别的类,如Initialize(),Update(),Get( ), 智者()。添加()等

谢谢,
Dmitri
All,

What are advantages and disadvantages of these two different approaches?

1 . I create a base class with a few virtual methods, then I derive my
classes from this class, override these methods and use this class.

2. I work with interfaces.

What is faster in .NET? I supposed that deriving from the base classes.

The main purpose was to create a few classes of the second level having the
same method names like Initialize(), Update(), Get(), Sage(). Add() etc.

Thanks,
Dmitri



如果你只想要相同的功能名称然后使用一个接口。如果您认为每个人都需要添加常用功能,那么

使用基类。


-

Michael Culley

" Just D" < no@spam.please>在消息新闻中写道:yGOzc.22
If you just want the same function names then use an interface. If you think you will every need to add common functionality then
use a base class.

--
Michael Culley
"Just D" <no@spam.please> wrote in message news:yGOzc.22


8r5.16@fed1read03 ...
8r5.16@fed1read03...
全部,

有什么优缺点这两种不同的方法?

1。我使用一些虚拟方法创建一个基类,然后从这个类派生我的
类,重写这些方法并使用这个类。

2.我使用接口。

.NET的速度更快?我认为派生自基类。

主要目的是创建一些具有相同方法名称的第二级别的类,如Initialize(),Update(),Get( ), 智者()。添加()等

谢谢,
Dmitri
All,

What are advantages and disadvantages of these two different approaches?

1 . I create a base class with a few virtual methods, then I derive my
classes from this class, override these methods and use this class.

2. I work with interfaces.

What is faster in .NET? I supposed that deriving from the base classes.

The main purpose was to create a few classes of the second level having the
same method names like Initialize(), Update(), Get(), Sage(). Add() etc.

Thanks,
Dmitri



这篇关于接口与虚拟方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆