Tag: inheritance

Qt是否支持虚拟纯插槽?

我在Qt中的GUI项目有很多“configuration页面”类,它们都直接从QWidgetinheritance。 最近,我意识到所有这些类共享2个公共时隙( loadSettings()和saveSettings() )。 对此,我有两个问题: 用这两个插槽编写一个中间基本抽象类(让它命名为BaseConfigurationPage )是否是有意义的虚拟纯方法? (每个可能的configuration页面将总是有这两个方法,所以我会说“是”) 在我做我的代码的重大变化之前(如果我必须):Qt是否支持虚拟纯插槽? 有什么我应该知道的? 这是一个描述一切的代码示例: class BaseConfigurationPage : public QWidget { // Some constructor and other methods, irrelevant here. public slots: virtual void loadSettings() = 0; virtual void saveSettings() = 0; }; class GeneralConfigurationPage : public BaseConfigurationPage { // Some constructor and other methods, irrelevant here. public slots: void […]

NodeJS中的JavaScript OOP:怎么样?

我习惯于Java中的传统OOP。 使用NodeJS在JavaScript中执行OOP的最佳做法是什么? 每个类是一个文件与module.export ? 如何创build类? this.Class = function() { //constructor? var privateField = "" this.publicField = "" var privateMethod = function() {} this.publicMethod = function() {} } 与(我甚至不知道这是否正确) this.Class = { privateField: "" , privateMethod: function() {} , return { publicField: "" publicMethod: function() {} } } 与 this.Class = function() {} this.Class.prototype.method = function(){} […]

为什么一个接口不能实现另一个接口?

我的意思是: interface B {…} interface A extends B {…} // allowed interface A implements B {…} // not allowed 我GOOGLE了,我发现这个 : implements表示定义接口方法的实现。 但是接口没有实现,所以这是不可能的。 然而,接口是一个100%的抽象类,抽象类可以实现接口(100%抽象类)而不用实现它的方法。 什么是定义为“接口”的问题? 具体而言, interface A { void methodA(); } abstract class B implements A {} // we may not implement methodA() but allowed class C extends B { void methodA(){} } interface […]

接口与抽象类

在C#中,什么时候应该使用接口,何时应该使用抽象类? 什么是决定性因素?

C#构造函数执行顺序

在C#中,当你这样做 Class(Type param1, Type param2):base(param1) 是先执行的类的构造函数,然后调用超类的构造函数,或者先调用基构造函数?

JavaScript基于原型的inheritance的好例子

我已经使用OOP语言进行了10多年的编程,但现在我正在学习JavaScript,这是我第一次遇到基于原型的inheritance。 我倾向于通过学习良好的代码学习最快。 什么是正确使用原型inheritance的JavaScript应用程序(或库)的写得好的例子? 你可以描述(简要)如何/在哪里使用原型inheritance,所以我知道从哪里开始阅读?

GetType()返回从基类调用时派生最多的types吗?

GetType()返回从基类调用时派生最多的types吗? 例: public abstract class A { private Type GetInfo() { return System.Attribute.GetCustomAttributes(this.GetType()); } } public class B : A { //Fields here have some custom attributes added to them } 或者我应该只是做一个抽象的方法,派生类将不得不像以下实现? public abstract class A { protected abstract Type GetSubType(); private Type GetInfo() { return System.Attribute.GetCustomAttributes(GetSubType()); } } public class B : A { […]

inheritance和recursion

假设我们有以下类: class A { void recursive(int i) { System.out.println("A.recursive(" + i + ")"); if (i > 0) { recursive(i – 1); } } } class B extends A { void recursive(int i) { System.out.println("B.recursive(" + i + ")"); super.recursive(i + 1); } } 现在让我们在A类中调用recursive : public class Demo { public static void main(String[] args) { […]

Objective-C多重inheritance

我有2个类,一个包含methodA,另一个包含methodB。 所以在一个新的类中,我需要重写方法methodA和methodB。 那么如何在目标C中实现多inheritance? 我有点困惑的语法。

一个接口可以在Java中扩展多个接口吗?

一个interface可以在Java中扩展多个接口吗?