Questions tagged [abstract-base-class]

In OOP (Object Oriented Programming), a base class that cannot be instantiated because some of its declared methods lack a definition, which is intended to be provided by derived classes. The term may have more specific or slightly different meaning according to the particular computer language involved.

109 questions
3
votes
1 answer

Getting all registered subclasses of an ABCMeta

I have a directory structure similar to the following: . ├── main.py ├── model.py └── models ├── __init__.py ├── model_a.py └── model_b.py model.py contains an Abstract Base Class: from abc import ABCMeta, abstractmethod class…
BioGeek
  • 21,897
  • 23
  • 83
  • 145
3
votes
1 answer

@staticmethod return value

In Python 3.6, I was trying to define a property in an AbstractBaseClass; my first try was something like this (later I discovered I can omit @staticmethod): class AnAbstractClass(ABC): @property @staticmethod @abstractmethod def…
entropiae
  • 85
  • 1
  • 6
3
votes
1 answer

C++ "Pure virtual method called" with use of abstract baseclass

I am using a abstract baseclass with only pure virtual methods, to have a interface behavior (yes, I am coming from Java) in C++. As far as I did my research this seems to be the way to go. I have to abstract base classes, GraphReader and…
nurgan
  • 53
  • 8
2
votes
1 answer

Error Related to FK in One-to-Many Relationship

I am using EF 5 Beta 2 Code-First. I have created an edmx file which has 2 entities among others named Brand and Vehicle. One Brand can have zero or more (many) Vehicles and every Vehicle should have a Brand (required). Vehicle has a foreign key…
2
votes
1 answer

Cloning Derived classes from Base classes

I have an Event base class with a DerivedEvent. I also have BaseA with DerivedA and BaseB with DerivedB classes. The B classes have A objects in them. the A objects update a queue of event pointers: std::queue> from the B…
road_to_quantdom
  • 1,341
  • 1
  • 13
  • 20
2
votes
1 answer

Django field clash with multiple abstract base clases

I am trying to define entity architecture that, if simplified, can be expressed like this: class M(models.Model): field_m = models.CharField(max_length=255) class Meta: abstract = True class A(M): field_a_1 =…
2
votes
0 answers

C++: Enforce Singleton on Subclasses of ABC

Whithin an already exisitng Simulation framework I am trying to implement the state pattern on already exising abstract base classes of models. As the model class is only an ABC, so should be the states. I am searching for a way to enforce the…
R.Tazke
  • 21
  • 1
2
votes
2 answers

I don't understand why it is wrong to test for possible interfaces in a base class

I have an abstract base class that will be used in hundreds of derived classes, including an additional abstract class. There are at least 2 properties (let's call them Purpose and Description, both strings) that will be added to many (but not all)…
DanK
  • 59
  • 7
2
votes
1 answer

C++ implementing abstract classes

I am trying to write a derived class called TerminalPlayer that inheritances a class Player given the declaration of virtual const Card playCard(const Card opponentCard) = 0; how would you implement the inherited playCard in the abstract class and…
TheWinterSnow
  • 175
  • 11
2
votes
3 answers

C++: How to create an abstract base class if class has no member functions?

I have an abstract base class, which serves the purpose of allowing an array of pointers to a base class to be created. (Useful for 'many things'...) My abstract base class contains no member functions. Therefore there are no pure virtual methods,…
FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225
2
votes
1 answer

Database structure to handle similar/same object at varying business levels

Scenario A well-known taco establishment wants to build a Django app with models Combo, ComboItem, Ingredient, and Order. Headquarters wants to create various combos with included items and layout the original item ingredients and price. Each…
2
votes
2 answers

Test that Python code only uses ABC methods

Let's say I have a function that is documented to take a collections.Sequence ABC. How do I test the code within this function against the ABC interface? Can I write a unit test (or tests) confirming that my code only calls methods defined by this…
detly
  • 29,332
  • 18
  • 93
  • 152
2
votes
1 answer

Why is __slots__ behaving differently in Python 2 and 3 when inheriting from an abstract base class

I created the following class to store changeable points on a plane in a memory-efficient manner - I need a mutable equivalent of namedtuple('Point', 'x y'). Since instance dictionaries are big, I thought I'd go for __slots__: from collections…
1
vote
2 answers

How do you initialize protected members of an abstract base class?

Perhaps I am worrying over nothing. I desire for data members to closely follow the RAII idiom. How can I initialise a protected pointer member in an abstract base class to null? I know it should be null, but wouldn't it be nicer to ensure that is…
John
  • 6,433
  • 7
  • 47
  • 82
1
vote
1 answer

Python: How to annotate a variable number of iterable attributes?

I have a class family for which I need to be able to iterate through attributes of type: Metric. The family consists of an abstract base class parent and child classes. The child classes will all have varying number of class attributes of type…
Archie
  • 333
  • 2
  • 9