Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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".

0
votes
1answer
68 views

Generically call static methods

I currently have two (core) classes : ...
1
vote
0answers
27 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
33 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 ...
6
votes
1answer
37 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
76 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
53 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
308 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
41 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
136 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
218 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
57 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
63 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
163 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
100 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
67 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
267 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
40 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
447 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
188 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
121 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 ...
7
votes
2answers
197 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
82 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
854 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
88 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
96 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
50 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
181 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
1answer
138 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
137 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
748 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
83 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
76 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
376 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
681 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
130 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
43 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 ...
1
vote
0answers
65 views

Printshop database design

I am trying to design multi purpose printshop database on which I will develop my basic store system. Beofre I tried to design it using EVL (Entity-Attribute-Value) aproach, however some users would ...
3
votes
2answers
562 views

Serializing a class hierarchy to JSON

I have a hierarchical object structure which needs to be converted to JSON. I have a following basic implementation of how it will be done: ...
0
votes
1answer
69 views

Java inheritance and generics [closed]

Today i had discussion with my colleague about casting. Our case: We have root class ...
3
votes
3answers
1k views

OOP modelling of a car agency

Exercise: A car dealer wants a computer system to manage the data of their vehicles and classify them by type. All cars have the following data Engine serial number Brand Year ...
3
votes
1answer
87 views

Vehicle inheritance exercise

I'm learning about using inheritance and super in Ruby. This is a continuation of one of the exercises that is in a book I am reading. I set up my Vehicle class to be the superclass. From there, <...
9
votes
1answer
2k views

OOP modeling of a boat rental system

I have some question about this exercise, did I model the problem correctly (the code works)?. If I did it correctly, Is there anything that can improve the code?. For example, how could I avoid the ...
5
votes
3answers
351 views

Inheriting from std::auto_ptr to support deletion of allocated arrays in C++98/C++03

[EDIT: Thanks for your opinions. I think this topic is discussed enough. Since std::auto_ptr is removed from C++17, I decided to drop the idea of inheriting from <...
-1
votes
1answer
609 views

How to avoid duplicate code due to the impossibility of using multiple inheritance

I'm working on a Spring - Hibernate App, and I have a question about how to correctly avoid duplicate code and using Hibernate, due to the impossibility of using use multiple inheritance (I usually ...
-2
votes
1answer
219 views

Parsing various types of message strings

Similar question MessageFormat: represents the various kinds of messages. (XML, JSON, ...