The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [inheritance]

One of the four pillars of object-oriented programming (OOP), inheritance establishes a "is-a" relationship between objects. For example, a "Cat" object can be treated in code as any other "Animal" object because a "Cat" is-a "Animal".

Filter by
Sorted by
Tagged with
2
votes
0answers
26 views

Inherited class calls initialization code in base class [closed]

I am interested in hearing your opinion on the approach I have taken to have inherited classes initialize their base class. Here's a Machines collection class from that maintains a list of Machine ...
1
vote
1answer
35 views

Using nullable properties in a base class for record selection in Table per Hierarchy - is there a better way?

I want to be able to list every Transaction associated with a Client in date order. ...
2
votes
1answer
81 views

Interface and inheritance; creating download types for a download manager

I'm creating a download manager in C# (in combination with Unity 2019.1.8, running the .NET 4.x equivalent (MONO) scripting back end). To accomplish this I decided to start using interfaces and class ...
2
votes
2answers
136 views

C# classes for system health metrics

My company wants me to build a serverless component (AWS Lambda) that checks every minute for our system components health. The data model (classes structure) I have devised so far is as pasted below....
1
vote
0answers
33 views

PHP Doctrine - shared properties between discriminator classes

I have a single table inheritance type on a class (Resource) that can be one of 3 classes: SingleDay MultiDay Accommodation SingleDay has properties: QTY ...
3
votes
1answer
2k views

Custom ResponseModel for Spring Controller - ResponseEntity<?>

I created a custom responseModel to have a standard json responseModel for some of my different RestController. Superclass TransactionResponseModel: ...
4
votes
0answers
23 views

Inherit docstrings from specified parent

I was recently working on some python where I was working with multiple inheritance and mixins and stuff like that, and I wanted to inherit docstrings for specific functions, from specific parents (...
1
vote
2answers
137 views

Is it normal to have a base type for Entities and Value Objects?

Please see the code below, which I am currently using in a production application. : ...
4
votes
1answer
97 views

Page-by model of data output and search results with values for UI

This is my first experience of designing classes with inheritance. I would like to get feedback on the interaction between the presented classes. It is unlikely that this code will seem complicated. ...
-1
votes
1answer
78 views

Class Inheritance in C# (possibly generics) [closed]

I'm working on a segment of code where it runs a number of tasks and then combine individual task results to construct a complete task result object, there's no concurrency involved so it's purely a ...
4
votes
2answers
126 views

Creating custom objects with custom properties using generics

I have two base classes: City and Building: ...
4
votes
1answer
38 views

Time interval class that enhances constructor argument handling of its parent class

I am making a subclass of a well-established python class: pendulum.Period, which overrides both __new__ and ...
10
votes
3answers
665 views

General purpose replacement for enum with FlagsAttribute

Enums with the FlagsAttribute have the disadvantage that you need to be careful when assigning their values. They are also inconvenient when you would like to allow ...
2
votes
1answer
66 views

Deserializing response to correct type

I use this method to get either Customer or Account. The server will determine which type it is. The response will have a property "Type": "Customer" or ...
2
votes
1answer
68 views

library having two types of books

I need to make a project related to a library catalog. It should have following methods relevant to these books: add delete list There are two types of books: novels and poetry. Both types have ...
-2
votes
1answer
46 views

Is it ok to use subclasses to define just a couple of attributes? [closed]

I'm working with some code left from other developers. Here we have several projects we can work with. The project object is instantiated at the runtime. Then it used in other classes. There are no ...
-1
votes
3answers
430 views

Design of Concept Class

I need to find the flaws in this design. So far the only ones i can think of are: No use of generics the class Concept uses a parametrized constructor, which means every sub class would need to pass ...
4
votes
1answer
65 views

Overriding List subscription to create IndexedHeap for Classical Dijkstra's Algorithm

Much of the academic exposition of Dijkstra's Algorithm (such as Wikipedia, or this class page from Darmouth) relies on your priority queue having the ability decrease the key of an entry: the ...
5
votes
1answer
76 views

“Detailed” exception class hierarchy

I'm designing an modular exception class hierarchy to use in various projects. I intend to inherit from std::exception in order to be maximally compatible with any ...
4
votes
4answers
3k views

An attempt at inheritance (Geometric Shapes)

I'm reading through the chapter on inheritance from C++ Primer 5th Edition. It asks Organize the following type into an inheritance hierarchy: (b) Geometric primitives (such as box, circle, ...
5
votes
2answers
88 views

Class hierarchy for objects in a 3D engine

I am writing my own 3D engine. I initially made the code quick and dirty but after a while the code became pretty messy and it have a lot of repeating code so I am currently cleaning up some of the ...
0
votes
1answer
79 views

Generically call static methods

I currently have two (core) classes : ...
5
votes
1answer
188 views

Wrapper to translate text in wxPython widgets

I am writing a wrapper for all widgets that contain text that needs to be translated for wxPython and make them handle the initial translation and the change of language on their own using gettext. I ...
4
votes
0answers
44 views

Safe pointer casting : static_cast or dynamic_cast

Context: I'm using the clone pattern for creating copies of polymorphic classes which may use virtual inheritance (I hope to get rid of the latter). So when calling ...
3
votes
0answers
82 views

A Node and a Socket, template or inheritance? [closed]

I'm trying to create a node based scripting/computation system. I've come up with 2 solution that seems to work. One involves template, the other one inheritance. Basically what I want to achieve is: ...
5
votes
1answer
46 views

List subclasses of a class

Description Given a class, return all its subclasses (recursively). As you can see I've eliminated recursion using a stack. What I want reviewed Is there a better way to do this? How can I make ...
1
vote
1answer
286 views

Write a class for Team which should have function to prints players details

I have written it using aggregation but i feel its not the best way we can do this. Please suggest is there any other way to do this. I think we can also built this without using player class, just ...
0
votes
1answer
67 views

Polymorphism and inheritance in C99

In the following code I have created the something like the behavior of inheritance and methods in C99 (without vtable). The code compiles without any warnings even with ...
3
votes
2answers
316 views

Implementing different types of light sources in a Graphics project

Edit: I got asked a lot why I need to have the LightSource base class or why do I keep one vector of all the light sources, so here's my explanation: In many ...
2
votes
0answers
69 views

Python logging setup for a package

I'm running a package that downloads data from the internet. This package makes logging calls from different modules. Suppose I have a package 'demopackage'. Here is how my logging is currently set ...
6
votes
4answers
14k views

Understanding interface with animal classes

I made this small program to demonstrate to myself an example of interface. I wanted to confirm whether it is correct and if there is anything more I should know about interfaces other than the ...
4
votes
3answers
166 views

Abstract classes in Blackjack game [closed]

From what I've read, I should use abstract classes when I want to define behavior for a superclass, and I don't want to instantiate the superclass. So, I'm making a Blackjack game in Java, and I want ...
14
votes
5answers
3k views

Mini RPG equipment code

what do you think about this code? It's upgraded version of: Classes representing items in an RPG game ...
0
votes
1answer
124 views

Initiating Child ViewController from UIStoryBoard in iOS

I'm trying to use inheritance in UIViewController where base class has XIB in storyboard. I'm troubling with initiating different children classes with that XIB. I ...
0
votes
1answer
557 views

A Java Quadrilateral Inheritance Hierarchy - revisited

This is an exercise from Deitel&Deitel's "Java. How to Program (Early Objects)", 10th edition. 9.8 (Quadrilateral Inheritance Hierarchy) Write an inheritance hierarchy for classes Quadrilateral, ...
5
votes
1answer
620 views

Making TypeNameHandling in json.net more convenient

Handling abstract types in json.net can be sometimes challenging because it requires a very long and complex syntax like: ...
2
votes
1answer
82 views

Managing different types of morphism and their compositions

Here's some code I wrote to manage the different types of morphism and their compositions in C++17. Let me know if you had any suggestions for substantial simplifications or improvements, or if I ...
33
votes
5answers
149k views

Implement a Shape abstract class

To learn more about OOP, @nhgrif challenged me to implement a Shape abstract class (more details in code remarks below. Here is how I did it. Any and all advice appreciated! Shape.java ...
2
votes
1answer
192 views

Boilerplate free registry/factory class for C++

I've made registry/factory class for C++ so I can instantiate different classes at runtime based on some kind of key. My design is partially based on this blog post: http://www.nirfriedman.com/2018/04/...
4
votes
1answer
105 views

Multiple games with same rpg-classes base [closed]

Please, if you find a better title, tell me because I really didn't know what to put in here! I like to guess how I could implement a game, and to be sure that my perception is working, I plan to ...
2
votes
0answers
80 views

Tkinter GUI Python implementation using classes

I'm really struggling to understand application of classes and best practices in fairly advanced level GUIs, and such an example could be extremely helpful. Please note that this is my first GUI ...
4
votes
2answers
5k views

Structure of inheritance between Animal classes and methods

I'm trying to do some basic inheritance between the 3 classes and use some simple methods, and I'm looking to learn what should be the correct structure between them and what can be improved. ...
1
vote
1answer
41 views

Proper naming for objects which have a position and bounds on a plane

I have an interface which is for an object which has bounds in a 2D plane. ...
3
votes
2answers
36 views

Build object with different input, using super-class and sub-class style, Python 3

I want to model a object of air, the temperature of which can be given in 3 different ways: if the value is known (assuming the temperature is a constant) if a curve of the values with different time ...
4
votes
2answers
578 views

C++ linked list inheritance hierarchy

I'm about to post quite a bit of code. Hopefully, someone is willing to put some time into reviewing it all. I know linked lists have been done a lot on here, but I wanted to improve the basic C++ ...
8
votes
1answer
15k views

Calculate area and perimeter for shapes: polygon, circle, rectangle and triangle

This is my project on inheritance and polymorphism. I have the main file from my teacher and built the project base on it. My base class is Shape. ...
5
votes
1answer
267 views

The rounded box that wanted to be an arc

This is from Bjarne Stroustrup's C++ Programming: Principles and Practice, Chapter 13 Exercise 2: Draw a box with rounded corners. Define a class Box, consisting ...
1
vote
0answers
204 views

E-commerce site for posting advertisements

I am developing an e-commerce website in ASP.NET MVC. Users can post advertisements of different types on the site. I am using inheritance to define my Ad types, and this review is mainly about ...
6
votes
1answer
165 views

Classes to manage perks to be added and removed

I am looking for code correctness and design usage as I think I might be over doing it in the class department. There are two things I'm mostly concerned with. The possible redundancy of classes ...
6
votes
2answers
201 views

(Almost) arbitrary base ints with decorated methods

After reading this question about returning the "next" string in some alphabet (the digits, followed by upper and lowercase ASCII letters) using Java, I thought, well that's just counting, so why not ...