abstract-class

Enum Bound to Database

不羁的心 提交于 2019-12-24 03:47:10
问题 When writing code for existing applications, often times the development database environment does not match the production environment - and even worse, there are times still where overlaying the environments is just not an option. One idea I had in mind to code for all environments would be to use a databound enum, whose values would be bound to the ID of the data item they represent. I couldn't get that to work with an Enum but I was able to solve it via abstract classes. For example:

Deriving a class from an abstract class (C++)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 02:42:26
问题 I have an abstract class with a pure virtual function f() and i want to create a class inherited from that class, and also override function f(). I seperated the header file and the cpp file. I declared the function f(int) in the header file and the definition is in the cpp file. However, the compiler says the derived class is still abstract. How can i fix it? 回答1: The functions f() and f(int) do not have the same signature, so the second would not provide an implementation for the first. The

How to enforce a subclass to implement a parent class' abstract methods using __init_subclass__ instead of ABCMeta?

泪湿孤枕 提交于 2019-12-24 01:15:24
问题 I have the following code to compare a base class' current (empty) implementation of required functions to its sub-classes, which must implement them in some different way in order to be considered acceptable at runtime. Without using a metaclass=ABCMeta and implementing @abstractmethod decorators on these base class methods, how do I go about doing this? For now, I'm writing the following __init_subclass__ hook on my ad-hoc, metaclass-less abstract base classes in multiple places in my

Abstract base class for derived classes with functions that have a return type of the derived class

馋奶兔 提交于 2019-12-23 19:22:39
问题 I would like to force a certain API for all classes derived from the base class. Normally, you do that using an abstract base class that has purely virtual functions. However, how do you handle functions that return the derived type? How do I go about forcing that type of function? struct base { virtual base func() = 0; }; struct deriv1 : base { deriv1 func(); }; struct deriv2 : base { deriv2 func(); }; This example will give an error like "invalid abstract return type for member function". I

How to inherit Mail.Thread AbstractModel and override function from this class in Odoo?

情到浓时终转凉″ 提交于 2019-12-23 16:34:38
问题 I would like to change something from mail.thread abstract class. So I inherited mail.thread and wrote override message_tracked function. But it did not call override function... just only called base function. Is it cause by mail.thread is Abstract Model? I tried like that osv.osv and osv.AbstractModel and import this py file in init .py and put 'mail' module in depend dic of openerp .py class mail_thread(osv.osv): _inherit = 'mail.thread' class mail_thread(osv.AbstractModel): _inherit =

Anonymous classes

故事扮演 提交于 2019-12-23 12:42:28
问题 In Java, it's common to write the following (e.g. for event handling) in order to make use of the template method pattern: abstract class SomeAbstractClass { public abstract void SomeFunction (); } //... SomeAbstractClass obj = new SomeAbstractClass () { public void SomeFunction () { /* implementation */ } }; In C++, the following compiles: class SomeAbstractClass { virtual void SomeFunction () = 0; }; // ... SomeAbstractClass * obj = new ( class : public SomeAbstractClass { virtual void

abstract class extends abstract class in php?

拜拜、爱过 提交于 2019-12-23 12:35:36
问题 I am working on a simple abstract database class. In my usage of this class, I'll want to have some instance be a singleton. I was thinking of having a abstract class that is not a singleton, and then extend it into another abstract class that is a singleton. Is this possible? Recommended? Edit: I want to have two abstract that are practically identical, except one is a singleton. So the only difference will be that one will have all the functions of the other, but will have the other

How to enforce a child class to set attributes using abstractproperty decorator in python?

主宰稳场 提交于 2019-12-23 09:41:19
问题 I want to enforce a Child class to set several attributes(instance variables), to achieve I am using abstractproperty decorator in python 2.7. Here is the sample code: from abc import ABCMeta, abstractproperty class Parent(object): __metaclass__ = ABCMeta @abstractproperty def name(self): pass class Child1(Parent): pass class Child2(Parent): name = 'test' class Child3(Parent): def __init__(self): self.name = 'test' obj_child1 = Child1() Child1 object creation gives an error as expected. obj

abstract classes without abstract methods creating objects in python

邮差的信 提交于 2019-12-23 08:11:40
问题 Basically, I knew that abstract base classes are used as skeleton classes just like regular classes, but enforces that abstract methods should be overridden by the child/inherited classes if it has one like below Class AbstractClass(object): __metaclass__ = abc.ABCMeta @abstractmethod def absmethod(self): pass class ChildClass(AbstractClass): def absmethod(self): print "Yeah!" obj = ChildClass() So we can create an object of ChildClass as above We know we can't instantiate an abstract class

Abstract class with default value

我与影子孤独终老i 提交于 2019-12-23 06:51:12
问题 I am trying to define a abstract Range class which will serve as the base implementation of a number of range classes. The intended use is irrelevant for this question, but so far I have: /** * Abstract generic utility class for handling ranges */ public abstract class Range<T extends Number> { // Variables to hold the range configuration private T start; private T stop; private T step; /** * Constructs a range by defining it's limits and step size. * * @param start The beginning of the range