我们应该将“替换实现”称为重写还是重写?是特定于语言的吗?


当前回答

如果你用另一个实现完全替换一个实现,这是“覆盖”,或者更常见的是“替换”。如果你在某些特定的情况下用另一个实现替换一个实现,这就是“重写”。

“覆盖”某物就是把其他东西放在它的位置上,破坏被覆盖的东西。“覆盖”某物是指在不伤害或改变被覆盖的东西的情况下,让其他东西代替它运行。

其他回答

我认为如果给一些上下文,就会更容易理解和区分。

APUE§10.17:

POSIX.1还指定abort将覆盖阻塞或忽略 对信号(SIGABRT)进行处理。

来自必应词典:

否决某事物:用你的权威否决某人的决定、命令、 等。

这里override的意思是它“忽略”上级的某些东西。 Abort并不替换进程的信号掩码,它只是“忽略”具有更高权限的约束。

所以我认为override和overwrite是两个完全不同的词。重写应该是替换旧内容的词。

The terms overriding and overwriting are often (conf)used in the context of object-oriented programming. (The fact that these words when pronounced in English by non-native speakers they sound similar adds to this confusion.) In object-oriented programming, thanks to the mechanism of inheritance, it is possible for subclasses to re-implement methods that were already implemented in a parent class. This is a powerful mechanism that enables fine-grained code and design reuse, because it allows to define subclasses that are special cases of the parent classes of which they inherit, with slightly specialised behaviour.

(方法)覆盖和(方法)覆盖之间的区别在于子类的方法如何重新实现在其继承的类中实现的原始方法。

如果已经存在的方法被一个全新的不连接到原始实现的实现所取代(通常实现一个替代的,但独立的,类似功能的实现),我们就称之为方法覆盖。

如果子类中定义的方法将方法的原始实现专门化为特殊情况,但以一种增量方式,通过使用super调用,我们就可以讨论方法重写。super调用的效果是执行由原始方法定义的行为,但除此之外,子类中的方法可以添加额外的指令来专门化该行为。

两者都是通用术语 Override是指防止以前的某个行为或决定,另一方面,Overwrite是指新写的东西覆盖了以前写的东西。

简单地说,

操作和决策将被覆盖。 信息被覆盖。

这是我对override和Overwriting的区别的理解,根据一个现实世界的例子:

假设你有一家汽车制造公司。你很有名,你的客户很满意,因为他们总是信任你,购买你的产品。

要继续你的业务,你基本上有两个选择:

All the things come through and you know that you step in the right path. So you want to not only keep the previous models but also keep enhancing them. Though, how come? Probably by adding some new features to the existing models! Now new models have all the features PLUS newly enhanced features. You know that the way you went through was sort of wrong! what an awful approach!! You notice quickly that the company should change the entire technology, otherwise it'll be undergoing harsh situations (like bankruptcy or so...)

毕竟,就编程而言,第一种方法指的是覆盖,因为你要在保留汽车原有行为的同时为汽车添加一些新的行为,而第二种方法指的是覆盖,因为你想完全改变行为,并从头开始开发新功能。

希望这能帮到你。

如果你用另一个实现完全替换一个实现,这是“覆盖”,或者更常见的是“替换”。如果你在某些特定的情况下用另一个实现替换一个实现,这就是“重写”。

“覆盖”某物就是把其他东西放在它的位置上,破坏被覆盖的东西。“覆盖”某物是指在不伤害或改变被覆盖的东西的情况下,让其他东西代替它运行。