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
-1
votes
1answer
62 views

Class Inheritance in C# (possibly generics) [on hold]

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
118 views

Creating custom objects with custom properties using generics

I have two base classes: City and Building: ...
4
votes
1answer
36 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
55 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
61 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
44 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
644 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
78 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
55 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
78 views

Generically call static methods

I currently have two (core) classes : ...
5
votes
1answer
67 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
41 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
43 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
81 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
58 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
312 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
54 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
154 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
386 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
73 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
84 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
170 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
75 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
445 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
521 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
200 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
185 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
198 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
84 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
999 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
100 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
153 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
159 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 ...
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
86 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
98 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
394 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 ...
1
vote
0answers
805 views

Marking a class as final or sealing a class

Which of these metaclasses should be preferred, and is there room for improvement? Some people are not familiar with the philosophies that come with working in Python and have a desire embedded in ...
1
vote
1answer
139 views

Implementing Abstract class

I used Pythons source code/documentation/textbook to come up with an abstract class and following subclasses. My requirements are: Domestic students don't require documentation International student ...
3
votes
0answers
41 views

Create, aggregate and plot signals using various methods for a given symbol using its historical data

I am hoping to get some help regarding code arrangement/organization using OOP concepts. My question is whether my usage of class/object selection/declaration and instantiation are sensible and what ...
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: ...
1
vote
0answers
44 views

TreeBuilder to handle various kinds of inputs for UI

I have to render a menu in tree structure in our UI. I am building the tree in the backend. The Tree can be built by taking many combinations of input parameters. So I created a hierarchy of Input ...