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
2answers
132 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 ...
4
votes
0answers
21 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 (...
4
votes
1answer
95 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
73 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 ...
2
votes
1answer
62 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
65 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 ...
10
votes
3answers
658 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 ...
5
votes
2answers
85 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 ...
4
votes
1answer
59 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 ...
0
votes
1answer
79 views

Generically call static methods

I currently have two (core) classes : ...
5
votes
1answer
73 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
0answers
43 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 ...
5
votes
1answer
44 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 ...
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: ...
0
votes
1answer
64 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
313 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
63 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 ...
4
votes
3answers
159 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 ...
0
votes
1answer
480 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, ...
2
votes
1answer
80 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 ...
0
votes
1answer
111 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 ...
2
votes
1answer
182 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
104 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 ...
5
votes
1answer
562 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: ...
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
552 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++ ...
1
vote
0answers
203 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 ...
1
vote
1answer
235 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 ...
6
votes
2answers
200 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 ...
6
votes
1answer
85 views

Object creation pattern for component classes

I've been grappling with Unity's architecture for the last few days, trying to work around the fact that you can't use constructors for your MonoBehaviours (and by ...
4
votes
3answers
1k views

C++ instance counter

I have created template class to easily get the current number of instances a class has. It's threadsafe and I tried to make it as hard as possible to abuse. ...
-1
votes
2answers
63 views

Healthy Characters

Let's say I have an abstract class Character that have fields health and maxHealth. maxHealth...
3
votes
1answer
90 views

Representing destinations in a square

I've written a program following the instructions of an exam paper. There are no solutions available so I would appreciate a feedback. I'm concerned with main in ...
11
votes
5answers
2k views

A simple program with trains and inheritance

Here it is my program. I'm especially worried about the main because I know that one must be careful while instancing vectors of "inherited" objects. The code I have works fine (as far as I can see) ...
5
votes
1answer
102 views

Classes to encode and decode images

I'm a developing a image processor, which reads a Base64 (compressed) image and writes its subimage to targets on threads. (Constructors, exception handling, and ...
5
votes
1answer
51 views

Class Item: A new Implementation to the qes already asked

This is a follow-up question to this: class-item-answer-to-one-of-the-unsolved-stack-overflow-qes. As per the comments I received from @Ben Steffan, I have re-written the above classes as follows. ...
5
votes
1answer
187 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 ...
-3
votes
1answer
161 views

Use inheritance to reuse toString/equals/hashCode [closed]

Does it bad practice inherit class to reuse toString/equals/hashCode (that actually based on reflection and use actual class field for it)? For example: ...
0
votes
1answer
180 views

Revealing module pattern modified for more class-like behavior

I've recently been learning about the revealing module pattern, and it seems like a really good way to structure code in many cases. However, I find myself wanting to use it like a class, so I'm ...
1
vote
2answers
133 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. : ...
6
votes
4answers
749 views

Better way to add fields to superclass in Java

I'm making my first steps in OOP and I'm currently doing some exercises. I've done a simple program with class structure like this (I'll provide only essential parts): Super class: ...
2
votes
1answer
87 views

Class hierarchy for informative exceptions in ASP.NET core

I have a base class called ExceptionPlus(please suggest a better name). Which is being inherited by multiple child class like BusinessNotFoundException, ArgumentInvalidException etc. My question is ...
1
vote
0answers
116 views

Sealing class attributes in Python

Over two years ago, someone asked a question on Stackoverflow about how to seal classes and attributes in Python after coming from a background in C#. The best answer to the question is that Pythonic ...
5
votes
0answers
406 views

Writing a metaclass to ensure a class is thread-safe

Python allows the creation of classes to be modified via metaclasses. They can perform all sorts of operations that might appear to be magical to languages that do not have the capability. The goal of ...