5,349 questions
Advice
1
vote
5
replies
31
views
Can an abstract class enforce trait usage?
I know we can have:
<?php
abstract class ExtendMe{
abstract public function implementMe(){}
}
Can we enforce trait usage?
<?php
trait MyTrait{}
abstract class ExtendMe{
abstract use ...
9
votes
1
answer
568
views
Is changing an abstract method to virtual a breaking change?
Let's say I have an abstract class with a public abstract method. If I make that method virtual instead of abstract (i.e. provide a default implementation), is that a breaking change?
I think not ...
Best practices
0
votes
11
replies
223
views
c++ abstract class : pure virtual covariant return
first I must says that I hate templates.... it makes unreadable complex code.... not speaking about 5000000 lines long error messages, with 10000 possibilities and that takes ages to understand for ...
10
votes
4
answers
758
views
Is there a widely used "tag" base class for C++ static classes?
In C++, there are some widely used zero-size base classes used for the purpose of "tagging" subclasses, for example boost::noncopyable.
Is there any that is used to mark a class non-...
4
votes
2
answers
144
views
How to override inject() dependency from abstract base class in Angular?
I have an abstract base class that used to accept a service via constructor injection:
export abstract class BaseEditEventClass<T> extends BaseFormClass {
constructor(protected _service: ...
-2
votes
2
answers
196
views
How to test the concrete method of an abstract class without manual subclassing? [closed]
I have an abstract Python class with a concrete method:
class AbstractFoo(abc.ABC):
def append_something(self, text: str) -> str:
return text + self.create_something(len(text))
@...
0
votes
1
answer
97
views
How to manage multiple JPA base entities (UUID, Long ID, Soft Delete) without redundant classes?
This question is likely already asked, but I am not satisfied with the answers. I add the link for reference.
Previous Question
Now, coming to the point, I have six different abstract classes which ...
1
vote
1
answer
52
views
How to implement images relationship with Abstract model in Django?
I'm working on a Django project where I have an abstract Post model that serves as a base for two concrete models: RentalPost and RoomSeekingPost. Both of these post types need to have multiple images....
3
votes
1
answer
766
views
Difficulty setting up threaded BST in C++
I'm having trouble implementing a threaded Binary Search Tree in C++. I have a non-threaded tree completely implemented (see below code). What I'm having difficulty with is setting the threads to ...
1
vote
2
answers
139
views
How to properly implement instantiation of an abstract class based on parameters
I want to create a class that is called from other methods and change the implementation of that class based on some context (like params):
Abstract class:
class PdfRenderer(ABC):
# Something else ...
1
vote
0
answers
112
views
Exclude methods consisting of a single pass statement from coverage reports in python
In my class, I have some methods that can be overridden by subclasses, but do not need to be.
I like to test my project and generate a coverage report using coverage.py.
Because the method of the ...
3
votes
1
answer
87
views
Obsolete marking for members about to become abstract?
The ObsoleteAttribute can be used in .NET to indicate that a given member or type is going to be removed in a future version. It will trigger compiler warning 612 or 618 on the code that uses the ...
3
votes
5
answers
225
views
Creating a list of types that derive from abstract class
I have classes ProgramA and ProgramB that derive from abstract class Program.
I sum them up into an array std::vector<Program*> and I pick a random one from there that runs for awhile.
#include &...
0
votes
0
answers
50
views
Abstract class with non abstract properties [duplicate]
I don't understand why this code compiles but it gives execution error:
Parameter specified as non-null is null: method kotlin.collections.CollectionsKt___CollectionsKt.minus, parameter
at kotlin....
1
vote
4
answers
168
views
Polymorphism and abstract classes in Java
Let's say I have the following classes:
public abstract class Animal {
public abstract void talk();
}
class Dog extends Animal {
@Override
public void talk() {
System.out.println(&...
1
vote
1
answer
124
views
Giving a type to polymorphic static methods used as public constructors
I have a number of classes all implementing the same interface. In order to create instances of these classes one should not use the constructor but rather a number of static methods which take a ...
1
vote
1
answer
53
views
How to bind to different abstract class implementations with additional properties without binding failure in WPF
I implemented the classes UtilityElectricityConsumptionModel and UtilityNaturalGasConsumptionModel from the abstract class UtilityConsumptionModel. The UtilityNaturalGasConsumptionModel just has the ...
0
votes
0
answers
27
views
How to Handle Feature-Specific Parameter Requirements in a Repository Pattern Implementation?
Best Approach to Handle Varying Parameters in Feature-Specific Implementations of an Abstract Repository in Dart
I have an abstract Repository<T> class in Dart that defines several methods, as ...
-1
votes
2
answers
118
views
Is possibility to derive from multiple interfaces the only difference between abstract class and interface?
In the past life was easy, interfaces could not have implementations, abstract classes could. Nowadays (like for 5+ years already lol), the only difference between abstract class and interface in C# ...
1
vote
1
answer
105
views
Pyre: `Invalid class instantiation` on a factory pattern with ABC type hint
I have implemented a factory pattern but Pyre-check trips over the type-hinting, thinking I want to instantiate the mapping dict type hint: type[MyClassABC]
Here is a minimum example, also a pyre-...
0
votes
1
answer
62
views
Implementing abstract classes
I am a beginner in Python coding and I try to learn abstract classes. I have a problem with implementing two exams which extend abstract class Exam, defining contract for diagnostic test.
class Person:...
-1
votes
1
answer
70
views
How does this keyword work in abstract class [duplicate]
I know that private field are not inherited, and when I am creating an object at line #2, the object is being created for Person and then when I set the fatherName, inside the setFatherName() how is ...
0
votes
1
answer
89
views
using typed template argument with default value as abstract class in c++
Using c++20, I have the following idea to generalize access to multiple chips in a circuit:
An interface should allow reading/writing to all chips with different address bits and register sizes (8, 16,...
0
votes
1
answer
44
views
Typescript: method cannot be added because of index signature?
I have an abstract class like the one below.
export abstract class BaseAPI {
static readonly [key: string]:
| ApiCall<unknown> // Defines a single API call with a generic response ...
1
vote
1
answer
71
views
Junit test cases for a method in Abstract Class which calls a method of its non-abstract Super class
I have a Parent Class Parent
class Parent{
public String calculate(String input){
// does lots of external system calls and complex calculations
}
}
Then I have an ...
1
vote
1
answer
367
views
Pylint unnecessary pass statement for abstract method
I have an abstract method which just includes a pass statement, as the method implementation is in another class that inherits from this abstract class. Here is the method:
@abstractmethod
def ...
-1
votes
1
answer
76
views
Calling Super function from child function
I have the following structure:
class grandparent(ABC):
@abstractmethod
def get_obj(self):
pass
class ParentBase(grandparent):
def __init__(self, obj1):
self.obj1 = obj1
...
0
votes
1
answer
68
views
Is it possible to truly "seal" a class function so it cannot be overridden in subclasses in any way?
Core question explained via code:
Say I have an interface
public interface IWorker
{
void DoWork();
}
Now, setup an abstract class implementing this interface. I want this abstract class's DoWork() ...
0
votes
0
answers
319
views
Force subclass to implement a class property in Python
I want to force all subclasses of a class to implement a property. As I understand it, I have to use abc methods for this use case. I tried the following:
from abc import ABC, abstractmethod
class ...
0
votes
2
answers
86
views
c# call generic method from abstract class passing inheriting type
I'm going to explain better what I mean.
I think what I desire is not possibile, however I'll try.
I have a static class who have this method:
public static class BaseTypeID
{
static ulong _id = 1;...
0
votes
1
answer
93
views
C# routine to create derived classes from an abstract class
I am trying to develop a routine that will run an sql statement and use the results to populate class objects that are derived from an abstract class, something like the following:
public static List&...
3
votes
2
answers
84
views
Getting the wrong value when using the override toString method
I am using an arraylist to hold different shape objects that are a subclass of an abstract superclass. The superclass contains two abstract methods: surface_area and volume respectively. After I add ...
-5
votes
2
answers
123
views
How to use abstract class as variable type in C# [duplicate]
I'm trying to use an abstract class as variable type in C# and getting System.StackOverflowException: 'Exception_WasThrown' error when try to read ResultData.ValuesDescription
public abstract class ...
0
votes
0
answers
32
views
If I have a child class that needs to add information to a parent's existing toString() override, how would I do that in C#? [duplicate]
This is my first question here, so hopefully I'm doing things right.
We have an assignment where we basically have to make a mini weather channel (it's supposed to be teaching us more about ...
1
vote
3
answers
169
views
Abstract Method override in Python
If I create an abstract class in python using abc with an abstractmethod as follows and create a concrete class which doesn't use def to override the abstractmethod but instead attempt to set the ...
1
vote
1
answer
39
views
Is there a way to ensure a function is called for every instance of a subclass inheriting from a base class?
OptionsAndAnswer is the base class.
abstract class OptionsAndAnswer(
...,
open val options: List<Option>
){
fun validate() {
require(options.map { it.id }.distinct().size == ...
2
votes
2
answers
75
views
Abstract Base Class property setter absence not preventing Class instantiation
I'm trying to get abstract properties to work, enforcing property getter & setter definitions in downstream classes.
from abc import ABC, abstractmethod
class BaseABC(ABC):
@property
@...
1
vote
2
answers
120
views
How to make sure a virtual method gets called just after the constructor?
I have a base class with an abstract virtual function fv() which is only implemented in derived classes. I want to make sure that the fv() of the derived classes is called in or immediately after the ...
0
votes
0
answers
18
views
Mark a method as "requires override" in Swift? [duplicate]
I want to have something like
class Parent {
@mustBeOverridden
func overrideThis(_ s: Source) -> Target {
// does not do anything, i.e. it is "abstract"
}
}
class Child1: ...
0
votes
1
answer
122
views
My generic class seems to not be *that* generic
I am currently creating a small plant caring game (Unity Engine 2022.3.40f1). It's properties (genes) are passed onto it's parts as a genome. These properties can be floats, integers or colors.
For ...
0
votes
2
answers
154
views
Templated constructor of abstract class without parameter type deduction in C++
I want my abstract base class to have a templated constructor, but can't get it to work without an extra parameter to deduct the type from.
I want to do something like this:
class Base {
public:
...
3
votes
1
answer
380
views
Creating a metaclass that inherits from ABCMeta and QObject
I am building an app in PySide6 that will involve dynamic loading of plugins. To facilitate this, I am using ABCMeta to define a custom metaclass for the plugin interface, and I would like this custom ...
0
votes
1
answer
63
views
Type-hinting a dynamically generated concrete subtype of an abstract class in Python
I have an abstract class, Float, that generates concrete subclasses dynamically. I would like to type-hint the return type so that the IDE knows that it's a concrete subtype of Float. That is, when ...
-1
votes
1
answer
94
views
pybind11 binding of a function with virtual class as argument or return type (solved)
here is an example of a code where i have a virtual class A, with its child A_2 and other classes/functions that have A as argument/return type. In use i could use instead A_2, A_3 ...
#include <...
0
votes
1
answer
128
views
C++ Best Practices: Serialization and Abstract Classes without library access
Preface: Serialization libraries cannot be used due to restrictions in the development environment, and the latest version usable is C++ 11.
I have various struct that need to be serialized and ...
1
vote
0
answers
30
views
Issue with Conditional Mapping in Abstract and Derived Classes Leading to EF6 SaveChanges Error
The OfType part of the query doesn't work as expected, and there’s an error when saving changes in the database.
Code:
using System;
using System.Data.Entity;
using System.Data.Entity....
0
votes
1
answer
98
views
Serializing and Deserializing abstract classes in YAML
Let's say we have a game, characters in which have special abilities. All abilities share an abstract base type called AbstractAbility. Each character has a list of said base type (List), elements of ...
0
votes
0
answers
47
views
Implementing Generics/Abstracts/Interfaces with serialization
I have a couple of classes that need to be serializable using DataContractSerializer, however I am trying to create a generic Class called XMLDocument, that allows for a WeatherData, RSSDocument, and ...
0
votes
4
answers
145
views
C++ with Qt5 : lock a common mutex before calling the actual override implementation of a method
I have an abstract class like this :
class Thing
{
public:
Thing();
virtual ~Thing();
static QMutex s_mutex;
virtual void load() = 0;
virtual void translate() = 0;
virtual ...
0
votes
0
answers
77
views
Optimal validation of an object in C++ if it receives raw data
I receive data entered by the user and I need to initialize a class with it that has an abstract parent class. I can do the check before initializing the class, but in this way the class validation ...