inheritance

Python subclass method to inherit decorator from superclass method

旧时模样 提交于 2020-02-03 19:49:57
问题 I have a superclass that has a retrieve() method, and its subclasses each implement their own retrieve() method. I'd like every retrieve() method to be decorated to cache the return value when it receive the same args, without having to decorate the method in every subclass. Decorators don't seem to be inherited. I could probably call the superclass's method which would in turn set the cache, but currently my superclass raises a NotImplemented exception, which I like. import json import

Odd Generic Inheritance pattern

梦想与她 提交于 2020-02-03 17:15:11
问题 During some research, I ran into an inheritance pattern using generics I have not seen before. http://thwadi.blogspot.ca/2013/07/using-protobuff-net-with-inheritance.html public abstract class BaseClass<TClass> where TClass : BaseClass<TClass> { //... } public class DerivedClass : BaseClass<DerivedClass> { //... } Usage: static void Main(string[] args) { DerivedClass derivedReference = new DerivedClass(); //this looks odd... BaseClass<DerivedClass> baseReference = derivedReference; //this

Odd Generic Inheritance pattern

元气小坏坏 提交于 2020-02-03 17:15:07
问题 During some research, I ran into an inheritance pattern using generics I have not seen before. http://thwadi.blogspot.ca/2013/07/using-protobuff-net-with-inheritance.html public abstract class BaseClass<TClass> where TClass : BaseClass<TClass> { //... } public class DerivedClass : BaseClass<DerivedClass> { //... } Usage: static void Main(string[] args) { DerivedClass derivedReference = new DerivedClass(); //this looks odd... BaseClass<DerivedClass> baseReference = derivedReference; //this

override virtual method with template method [duplicate]

痞子三分冷 提交于 2020-02-03 04:43:05
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Can a member function template be virtual? In a base class, the function my_func is defined as virtual. However, in the derived class I would like to have my_func to be a template method. Is this possible? It seems it isn't. I get the error "cannot allocate an object of abstract type" , which I believe it is related to the fact that the compiler does not acknowledge the override of the virtual my_func in the

Accessing base member functions in class derived from template class [duplicate]

元气小坏坏 提交于 2020-02-02 06:10:33
问题 This question already has answers here : Why do I have to access template base class members through the this pointer? (3 answers) Closed 5 years ago . I am developing a library at my work and I have designed a complicated inheritance that includes template classes and deriving from them. My problem is that a base template class has virtual overloaded operator that takes 2 arguments and returns some value. In base class this operator is implemented and most of derived classes does not

Unrecognized selector for NSManagedObject base class

馋奶兔 提交于 2020-02-01 08:35:06
问题 I am getting an 'unrecognised selector' exception when calling a base-class method on an instance and can't see what the problem is. I have an object called Form as follows: #import <Foundation/Foundation.h> #import <CoreData/CoreData.h> #import "HPSDbBase.h" @interface Form : HPSDbBase @end The base class for Form looks like this: #import <CoreData/CoreData.h> @interface HPSDbBase : NSManagedObject @property (nonatomic, retain) NSString * id; @property (nonatomic, retain) NSString * json; -

what must be implemented from an abstract class in java?

拜拜、爱过 提交于 2020-02-01 04:34:05
问题 I have two questions really. I'm trying to get a handle on how inheritance works. If I have an abstract class to inherit from, and it has a method that is not labelled abstract does this method still need to be implemented in the subclass? If I have a subclass that is inheriting from another subclass, which is then inheriting from an abstract class, does the lowest subclass need to implement the methods in the abstract class? Or because the methods have been implemented in the middle subclass

Constructor and Destructor Inheritance

♀尐吖头ヾ 提交于 2020-02-01 04:05:08
问题 I believe Constructors and Destructors in base class cannot be inherited by derived classes of the base class. Is my understanding correct. 回答1: Your understanding is correct. For example, if you have class Base { Base(int i) {} }; class Derived: public Base {}; Derived d(3); This will not compile because the Base constructor is not inherited. Note that default and copy constructor are created by the compiler if possible, and call the corresponding constructor of base classes, therefore for

Overriding private methods in (non-)static classes

无人久伴 提交于 2020-01-30 12:54:28
问题 I have this test code example: public class Test { private static class Test3 { private void print1() { System.out.println("1"); } } private static class Test4 extends Test3 { private void print1() { System.out.println("2"); } } public static void main(String[] args) { System.out.println("Overriden call to private method ----------------"); OuterTest.Test1 test1 = new OuterTest.Test1(); OuterTest.Test2 test2 = new OuterTest.Test2(); OuterTest.Test1 test12 = new OuterTest.Test2(); test1

Scala, class using mutable var, update in overriding method

房东的猫 提交于 2020-01-30 12:35:58
问题 I am having a hard time understanding how to get the following code structure to work. In Scala I have a class MyClass which inherits from SomeClass I added a var member variable in this case called mutableArray and it is being updated in the overridden method overridingSomeClassMethod and is called when I create a new instance of the MyClass a number of times right away. But in main when I try and get the updated mutableArray variable it prints out the instantiated var as if it is immutable