Skip to main content

Questions tagged [inheritance]

Inheritance is the system in object oriented programming that allows objects to support operations defined by anterior types without having to provide their own definition. It is the major vector for polymorphism in object-oriented programming.

inheritance
-1 votes
0 answers
31 views

Error inheriting non pure virtual function from class that implement another class

In my code i have this three classes, i'm using the visual studio compiler and it's compiling without any error and runs fine. But i don't need the methodes width and height in my interface IBrick, if ...
Danilo Namitala's user avatar
-2 votes
0 answers
55 views

Is there a way to make my compiler warn if my method-call explicitly calls up to a non-direct-parent superclass? [duplicate]

Background: After some careless refactoring, the following dumb mistake crept into my codebase, resulting in a somewhat-hard-to-track-down runtime misbehavior: class Grandparent { public: void Foo(...
Jeremy Friesner's user avatar
1 vote
1 answer
72 views

How to provide a 'blanket implementation' of a static method for the derived class?

Consider this: struct Base { static Base make() { return {}; } }; struct Derived : public Base { // I _would_ want to have a `static Derived make()` automagically here }; One approach to the ...
Mike Land's user avatar
  • 480
0 votes
0 answers
24 views

Lua: Assistance Needed in Using Inheritance in conjunction with case-insensitive metatables/metamethods? Doable?

I've been trying to wrap my head around utilizing inheritance with Lua (https://www.lua.org/pil/16.2.html and Case insensitive array in Lua as references) but also integrating a case-insensitive ...
Spiderkeg's user avatar
0 votes
1 answer
33 views

Composable inheritance... how to add padding to inherited content?

I want to do some kind of Composable Inheritance. I need a parent composable with a Scaffold, and the children must have the inner content to the scaffold. How can I apply the innerPadding to the ...
NullPointerException's user avatar
0 votes
3 answers
91 views

Inheritance of C# functions and using reusability

I'm drawing a complete blank on what to actually call what I want to do (hence the difficulty I am having in trying to research it). But what I do have is this: public interface IShapes { public ...
John Barber's user avatar
2 votes
1 answer
85 views

How to return smart pointers and covariance in C++

I am following this tutorial to understand how to return smart pointers and covariance in C++. #include <memory> #include <iostream> class cloneable { public: virtual ~...
GPrathap's user avatar
  • 7,650
-1 votes
0 answers
20 views

Need to extract a method to use in equals implementation with Hibernate DTO's

I am updating a Java project and had to add an equals() implementation 3 java DTO files (call them Child1, Child2 and Child3) which all extend the DTO Parent class. IntelliJ generated the following ...
ponder275's user avatar
  • 923
4 votes
1 answer
94 views

Assign base object without changing inherited ones?

How valid is it to assign a new object to a base one, without changing the inherited ones? The example below works as expected, but is it by chance? This example is simple, but is there any situation ...
T.L's user avatar
  • 684
-2 votes
1 answer
54 views

When calling an inherited method from a derived class it tries to use the uninitialised fields of the base class [closed]

I have two classes. One called Agent, and the other called Player. Agent is the base class and Player is the derived class. When calling the function SetHand() from the derived Player class, I run ...
inThe-FLesh's user avatar
0 votes
0 answers
14 views

Declaring an interface property as a derived type [duplicate]

Currently I have a series of services/repos that are allowing a generic of a custom type. I want to add a generic list to that interface such that when a class inherits the interface it can apply a ...
Ian's user avatar
  • 71
-1 votes
0 answers
34 views

invalid covariant return type for [duplicate]

Consider the following example, which is some part of the bigger codebase, in the getInstance() if I dont return a pointer to the derived class, i.e., just void or int or a different type, the ...
GPrathap's user avatar
  • 7,650
-1 votes
0 answers
32 views

Does a socket instantiated in a parent class belong to its child class?

I'm making a messaging service in java where I'm using sockets and object input/output streams. I wanted to make this as object oriented as I can (to learn OOP) so for the client side I'm making an ...
Cyberdrum's user avatar
0 votes
1 answer
54 views

What are the differences between using mutiple or'ed typehints vs abc and an inheritance hierachy in Python?

Python is a dynamic language. This means that types are dynamic at runtime and Python makes use of the concept of Ducktyping. What this means is that for any object x was can do x.some_function() x....
FreelanceConsultant's user avatar
1 vote
1 answer
42 views

Inherit override-equivalent as different methods

Several methods from interface, super class or new method are override equivalent. I need to make different realization for each. Example: public interface A { int f(); } public interface B { ...
Andrew's user avatar
  • 15
1 vote
0 answers
30 views

how to use a foreingkey field in a Multi-table inheritance?

Currently the code is working for me, however in admin panel it is not displaying the information in the fields. I assumed that the information that had been entered in the parent table would be seen ...
user25336866's user avatar
0 votes
1 answer
46 views

"Error creating form in Unit...fmx: FMX datamodules not supported." when inherit from TDataModule descendant class

I have a problem (with sample project). I have a TDataModule derived class to which I have added some properties and methods. I wanted to make sure that it was possible to create a new instance of ...
Maurizio Del Magno's user avatar
3 votes
1 answer
48 views

Multiple constructors annotated with Lombok @Builder cause a problem?

This is my first question, so please feel free to correct anything that I missed writing this question:) I am having trouble with using the @Bulider with my DTO objects. I have an abstract class "...
Doh Kun Lee sanity's user avatar
-2 votes
0 answers
55 views

a constructer declared in a type with parametere list must have 'this' constructor inisializer error [closed]

I'm working on a C# project where I have an abstract base class Employee with a parameterized constructor Employee(string name). My derived class FullTimeEmployee has a constructor that takes three ...
Smoker's user avatar
  • 1
0 votes
1 answer
34 views

Why is inheritance using constructor functions "hard to do properly" (MDN)?

The MDN's article for "Inheritance and the prototype chain", under "Different ways of creating and mutating prototype chains": "With constructor functions", gives the ...
Aayla Secura's user avatar
0 votes
0 answers
44 views

How to alter WPF button color from the Code not user input (click) [closed]

I have a WPF application that allows users to pick a test to run. We have 3 tests called Test1, Test2 and Test3. All these tests inherit a model called TestModel. TestMoel contains common properties ...
varun's user avatar
  • 1
-1 votes
0 answers
32 views

Polymorphism in Java Spring [closed]

I develop an application in Java Spring. I have an abstract superclass called AbstractPuzzle and I have its children called Wordle and Riddle(I have JOINED type of inheritance). I get an ...
rxvxl's user avatar
  • 1
2 votes
0 answers
66 views

Base class not recoginsed while using wild card generic

Why is the below not working? A b1 = new B(); Function<? super B, ? extends A> function = x -> new B(); A apply = function.apply(b1); It gives an error "Required type capture of ? ...
Sijo Kurien's user avatar
3 votes
1 answer
68 views

Why objects having instance of a class with private property in prototype throw when accessing private member?

Consider this code: class Klass { #priv = 42 get pub() { return this.#priv } } // these two correctly return 42 console.log(new Klass().pub); console.log((new class extends Klass {})....
Bartosz Gościński's user avatar
1 vote
0 answers
29 views

Complex multi level EF Core 8 inheritance issue

Please consider the following: DB Context: // DbContext.cs public partial class OperationsDbContext : DbContext { public virtual DbSet<AnimalBase> AnimalBases { get; set; } public virtual ...
Mejenborg's user avatar
1 vote
2 answers
37 views

Angular component inheritance: will @Component decorator metadata inherited?

I have a parent-component like this: @Component({ template: "", changeDetection: ChangeDetectionStrategy.OnPush, }) export class ImYourFather {} Now I also have two inheritance ...
jaheraho's user avatar
  • 510
5 votes
3 answers
170 views

Initialization order of inherited constructors

I have this example: #include <iostream> #define print(X) std::cout << X << std::endl struct B1 { B1(int _i = 5): i(_i) { print("B1 constructor"); }; int i; }; ...
mada's user avatar
  • 1,932
-2 votes
2 answers
67 views

How do I create a member that can accept 2 very similar interfaces?

I currently have two classes that do exactly the same but have differences of a single member. interface interfaceA { VariationA getVariation(); } interface interfaceB { VariationB ...
תומר ש's user avatar
0 votes
0 answers
21 views

OpenAPI Swagger with kotlin inheritence

How to deal with inheritence with Kotlin for Swagger targetted objects? Just wondering if there is a way to do something like @Schema(description = "Child.") class Child( aName: String ):...
Pipo's user avatar
  • 4,963
0 votes
1 answer
43 views

inherit constructor and factory in flutter

I'm learning flutter and I'm trying to turn requests results into more convenient objects, so I created the basic schema of a response (which is not supposed to be instantiated anytime) : class ...
n3wbie's user avatar
  • 1,126
0 votes
0 answers
27 views

Assigning my custom class to an object/widget from a .ui file [duplicate]

Writing my 1st code in python, how can I create an instance of a class of my own and assign it to an object/widget from a .ui file? Something like this: import sys from PyQt6.uic import loadUi from ...
eli's user avatar
  • 29
-1 votes
1 answer
28 views

Why does the custom ArrayAdapter constructor in this example not match the superclass constructor exactly?

I was following a tutorial on creating a custom ArrayAdapter for a ListView in Android. Here is the custom adapter class from the tutorial: public class NumbersViewAdapter extends ArrayAdapter<...
minh's user avatar
  • 27
0 votes
1 answer
58 views

Provide implementation for an abstract method from an interface

Is it possible to override a method implementation by deriving from an interface which gives a default implementation for that method? If not, how should I restructure my code to avoid explicit method ...
Elia Giaccardi's user avatar
-1 votes
1 answer
41 views

Java Protected Field Access Issue in Subclass

What is the difference between public, protected, package-private and private in Java? The question's answer cannot answer my question. It's not a duplicate question. I totally know the diagram of ...
maplemaple's user avatar
  • 1,435
0 votes
2 answers
48 views

How to upgrade Java class to extension class?

I have a simple problem. I have a large class: public class Base { public Field1Data field1; public Field2Data field2; public Field3Data field3; // many more fields later... public ...
tuskiomi's user avatar
  • 183
0 votes
1 answer
41 views

Overriding implementation of a library Component

The problem (Angular 14) I want to override a function from a library Component (Angular Material) without re-implementing the whole component. The idea My thinking is inspired by one of the examples ...
Sulejman's user avatar
0 votes
2 answers
62 views

multiple inheritance without defining a class [duplicate]

I'm not sure that's possible, and I'm wondering if that's the way to go, or if there exists a better way of doing that. I'll create a toy example to expose what I'm looking for. Suppose I have people ...
Elerium115's user avatar
1 vote
1 answer
87 views

Inherited functions returning self reference with derived type

I am trying to create a system where one base class has a bunch of functions, then derived classes can inherit it and add more functions. However, all of these functions return the this keyword and I ...
CreeperCrafter979's user avatar
-1 votes
0 answers
56 views

Compiler misidentifying/unrecognising type [duplicate]

I have the following class with constructor: command.h: #include "./robots.h" enum class CMD { //...... }; class CommandTemplate { //..... public: virtual std::unique_ptr<...
steve89's user avatar
1 vote
3 answers
81 views

Inheriting Structs in C++

I am working with the LibAV library, converting it from C to C++ (and moving to an object oriented style). This library has structs to hold data, which need to be created using specific allocation ...
ThomasNotTom's user avatar
0 votes
0 answers
56 views

C++ continue base class bitfield in derived class

I have a base class with a bitfield enum Enum { ENUM1, ENUM2, ... ENUM8 }; struct Base { Enum type : 3; }; I am inheriting a class struct Derived : public Base { bool bf1 : 1; u32 bf2 : 19,...
Evgeny Ilyin's user avatar
2 votes
2 answers
88 views

How to declare a function parameter to accept all derived types of a generic abstract type?

these are base type [DataContract] public abstract class InputModelBase<T>where T : InputModelParametersBase { [DataMember] public string Token { get; set; } [DataMember] public ...
FDB's user avatar
  • 1,055
2 votes
1 answer
48 views

How does __slots__ inheritance work? (My code works and I don't know why)

Here is the example of my implementation: class FileHandler: __slots__ = ("_target_path",) def __init__(self, target_path: Path) -> None: self._target_path = target_path ...
Todor Naydenov's user avatar
0 votes
0 answers
24 views

Automapper mapping to derived type based on predicate when base class is not abstract

I need to map a model to a derived class based on a condition, but otherwise map to another class. for example if I have these classes class Shape { } class Rectangle : BasePolygon { } class Square :...
Moniker's user avatar
  • 135
0 votes
1 answer
46 views

DRY - Derived class with static methods

In Unity C#, I have a base class Baker, it's derived from ScriptableObject, and I'm deriving from it CakeBaker, BreadBaker, PieBaker. ScriptableObjects can only be created statically, using ...
TheUmpteenth's user avatar
0 votes
1 answer
41 views

Antlr grammars that generate actual class inheritance

Need to know, is it possible to generate parsers, lexers, listeners, etc, by importing subset-grammars? I see that the supergrammar subgrammar pattern is possible, but I'm not sure I see a true class ...
Michael W. Powell's user avatar
-2 votes
1 answer
58 views

Cast a List<derivedType> into a List<baseType> without breaking the reference

I have multiple lists of type ArmorBase and WeaponBase that inherit the ItemBase class. I also have a List that represents the current selected item List public List<ItemBase> ...
Bruno Pasini Fiorini's user avatar
-4 votes
2 answers
55 views

I don't want to call the parent constructor. Can we do something about this? [closed]

I am trying to explore JS classes and I am getting error if I am not calling super(). ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived ...
Tazeen Khan's user avatar
1 vote
3 answers
75 views

If I already have an instance of a super class, how can I create an instance of a child class from it?

How do I properly inherit data from an instantiation of a super class? For example, consider something I can get to work, but is confusing in its behaviour: from dataclasses import dataclass from ...
bzm3r's user avatar
  • 3,770
0 votes
0 answers
16 views

Efficient design solution for handling dynamic marking schemes with multiple levels and subjects

We're developing a grading system for a school with multiple levels (e.g., elementary, middle school, high school) and various subjects within each level (n subjects < 200). The challenge is that: ...
shithanshu mishra's user avatar

15 30 50 per page
1
2 3 4 5
855