非虚方法 - 为什么? [英] Non-virtual methods - why?
本文介绍了非虚方法 - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
在哪种情况下将方法声明为非虚拟方式是合适的?
Thanx,
Adrian。
解决方案
" Adrian Herscu" < BM ***** @ hotmail.com>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...大家好,
在哪种情况下将方法声明为
非虚拟是合适的?
任何时候a)安全性可以被证实,b)稳定性可能是
comprimised,c)不可能编写一个无法覆盖的方法
安全(与a& b相关)。
Thanx,
" Adrian Herscu" < BM ***** @ hotmail.com>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...大家好,
在哪种情况下将方法声明为
非虚拟是合适的?
任何时候a)安全性可以被证实,b)稳定性可能是
comprimised,c)不可能编写一个无法覆盖的方法
安全(与a& b相关)。
Thanx,
任何时候你希望基类方法保持不变
覆盖它继承人。
:)我认为你来自Java,其中所有方法都是虚拟的
默认,无论如何它为代码增加了一些清晰度。
-
Horatiu Ripa
" Adrian Herscu" < BM ***** @ hotmail.com>在消息中写道
新闻:#y ************** @ TK2MSFTNGP09.phx.gbl ...大家好,
在哪种情况下将方法声明为
非虚拟是合适的?
Thanx,
Adrian。
Hi all,
In which circumstances it is appropriate to declare methods as non-virtual?
Thanx,
Adrian.
解决方案
"Adrian Herscu" <bm*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...Hi all,
In which circumstances it is appropriate to declare methods as non-virtual?
Any time that a) security could be comprimised, b)stability could be
comprimised, c) its not possible to write a method that cannot be overriden
safely(related to a &b both).
Thanx,
Adrian.
"Adrian Herscu" <bm*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...Hi all,
In which circumstances it is appropriate to declare methods as non-virtual?
Any time that a) security could be comprimised, b)stability could be
comprimised, c) its not possible to write a method that cannot be overriden
safely(related to a &b both).
Thanx,
Adrian.
Anytime you want that the base class method to remain unchanged by
overwriting it in inheritors.
:) I presume you came from Java where all the methods are virtual by
default, anyway it adds some clarity to the code.
--
Horatiu Ripa
"Adrian Herscu" <bm*****@hotmail.com> wrote in message
news:#y**************@TK2MSFTNGP09.phx.gbl...Hi all,
In which circumstances it is appropriate to declare methods as non-virtual?
Thanx,
Adrian.
这篇关于非虚方法 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文