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".
306 questions
-1
votes
1
answer
117
views
Am I overusing classes and/or OOP features? [closed]
I have a very class heavy approach to writing C++ code, which I don't think is necessarily wrong. However, I often use classes without knowing if I actually need them, which I feel leads to making ...
0
votes
1
answer
109
views
Implementing safe custom exception [closed]
I was trying to come up with some design to subclass built-in exceptions.
For simplest case I used something like this:
...
9
votes
3
answers
630
views
Parsing SFV files to extract and store the hashes
Similar to the class for the RAR file, now a class to extract and store the hashes from SFV files.
Though this was considerably easier, there has been some code reorganisation: there is now an ...
5
votes
2
answers
341
views
ostream that counts and discards the characters written to it
The code below implements a class, CountingOStream, whose job is to
count the number of characters written to it while also discarding those
characters and ...
2
votes
0
answers
80
views
Classes for Config and logical operators
I have a spring cloud gateway application with this yml structure for request validation:
...
2
votes
0
answers
178
views
"Better" enumeration for C#
I've been looking to have "smarter" or "better" enum functionality in C#. There are a few GitHub/NuGet projects out there, but they seem to target newer versions of .NET and I ...
1
vote
1
answer
252
views
Python3 currency abstract class (without the permission to be instantiated directly)
I'm a newbie python developer who accidentally studied the concept of
Abstract classes
and I found it pretty much helpful to implement due to the SOLID principles.
At the very moment of testing and ...
2
votes
1
answer
111
views
Python 3.10+: an exploration of meta classes and subclasses through the lens of metric (SI) prefixes with subclass-able units and changeable bases
Problem Statement
From the National Institute of Standards and Technology's Office of Weights and Measures, one can find a handy list of all the metric prefixes:
e.g.
Purpose
Name
Symbol
Factor
Name
...
0
votes
1
answer
293
views
Calling the base method from overriden method to add some functionality
I have a small Linked list program which I created for just brushing up the concepts.
Following is my Node class
...
1
vote
2
answers
100
views
Extend native `Array` instances
I need/want to extend created array instance, to add extra methods that i see as useful.
class.labels.js
...
4
votes
1
answer
433
views
Abstract base class for binary serialization
Ensuring that some logic is always being run before the user's overriding methods.
I'm writing a library and I have some abstract classes that can be binary serialized (and users can subclass them and ...
2
votes
1
answer
542
views
Statically allocated buffer using templates
I want to have some classes that would contain arrays of different sizes. I want this to be statically allocated because it is intended for an embedded system. The only good solution I can think of is ...
2
votes
1
answer
98
views
Reversing a type converter with minimal redundancies
The objective is to implement the reversed version of StringToDoubleConverter but without writing too many redundancies. I love DRY (Don't Repeat Yourself) design ...
0
votes
1
answer
514
views
Class that counts its instances
I'd love some feedback on the C++ base class shown below. It's basically a toy problem for a fake video game where the monsters that you have to avoid will all be sub-classed from the class shown ...
2
votes
0
answers
130
views
A Python base class for a family of Postgres server manager classes
I'm working on a repo the purpose of which is to create and manage a local PostGIS server. (PostGIS is a bit niche, but it boils down to a few extra spatial data types and built-in SQL function. With ...
6
votes
2
answers
1k
views
Classes representing 2D points and pixels
How can I improve this code or make it tidier?
...
0
votes
1
answer
246
views
C++20 Wrapper class for an unsigned integer type and a templated derived class that codes modular arithmetic type
The context is a library to represent numbers (in this case integers) by wheighted position by radix powers for every radix R, passed as template argument. These derived types are digits of radix R, ...
2
votes
1
answer
1k
views
Java implementation of Employee class hierarchy
We were tasked to do this assignment where there is the base class employee and two derived class part-time and full-time employees. Here is what I came up with:
...
3
votes
0
answers
137
views
Build the Mountain Car Environment using coupled inheritance and type annotations
This code builds the environment for the standard Mountain Car Problem of reinforcement learning.
I'm using Python 3.9 with PyCharm and I'm wishing to use type annotations throughout. I'm trying to ...
2
votes
1
answer
104
views
Extract Excel or CSV and convert to JSON: analyze these classes with class diagram
Please review my code and give some improvement suggestions.
I wrote code but not to the best standards. I think this site gives some valuable suggestions.
This code is for extracting ...
4
votes
4
answers
3k
views
Model animals using inheritance in Java, revised
Yesterday I posted my first solution to an interview problem here. I am now aware that I have many weak spots in Java and need to do extensive review before tackling any more interviews. Having said ...
1
vote
1
answer
504
views
Model animals using inheritance in Java
I was assigned the following problem:
You've gone back in time to 500BC Athens and Socrates wants you
to build him an app to help classify animals.
Build the classes ...
-1
votes
2
answers
106
views
Simple Vehicle speed representation [closed]
This code models two vehicle types, with a method to accept a string representing a boost to change speed.
How can I optimize performance in inheritance child class?
How can I reduce the code inside ...
1
vote
1
answer
2k
views
C# Coffee Machine
I saw this post and tried to do my attempt. This is the requirement of task:
Design a coffee machine which makes different beverages based on set
ingredients. The initialization of the recipes for ...
1
vote
1
answer
525
views
Reading data from multiple different resource bundle property files in Java
I have class structure to read the data from resource bundle (property files).
...
3
votes
2
answers
221
views
Pool of Thread Pools
I had a problem at my work that we have some tasks that need to be executed as fast as possible. To do this we implemented them so they are multi-threaded in an ExecutorService. Originally we had for ...
0
votes
1
answer
60
views
Deduplicate << operator implementation on inheritance
I have the following working code:
person.h
...
3
votes
2
answers
471
views
Alarm clock subclass of a clock
I have these two classes and they should remain separate classes, but I have a feeling that this could be implemented more efficiently and with less duplicate code. After googling around I still didn'...
1
vote
2
answers
3k
views
Ensuring that attributes referenced by a mixin are present in the children class
I have implemented the below _get_schema method to ensure that schema attribute is always present on the ...
5
votes
2
answers
519
views
Best approach for the Design Pattern for multiple schedulers using interface and abstract class
I have a requirement to fetch data for different types of Users (Customers, Publishers etc) for three different timelines (retro, current, and past), all have different URLs. There is a scheduler ...
2
votes
0
answers
105
views
what should be the best approach to follow DRY principle here
My first component
...
2
votes
3
answers
331
views
Builiding a Model from Stored Procedures
After reading that Data Classes can be considered a code smell, I am shifting from a pattern with many data classes and a single manager class that handles all the instantiation of the classes, to a ...
2
votes
1
answer
238
views
Noughts & Crosses (Final Version)
I've made a major update to my Noughts & Crosses program, this ISN'T a duplicate! I know it's not good to use system("pause") and system("cls"), however, I just wanted to make ...
6
votes
2
answers
193
views
FizzBuzz game, open to any critiques
I made this FizzBuzz game for my college class and it's kind of ridiculous, but is suppose to demonstrate chain of command so writing it in a little forloop was out of the question. In case you don't ...
3
votes
1
answer
87
views
Colour-model classes using CRTP
I want to implement color space logic.
So I started with creating some structs:
...
4
votes
0
answers
2k
views
View Binding with Base Classes
UPDATE: After getting "a kind of" affirmation from various platforms( my discussions on twitter, reddit, other stack overflow posts,etc) I have written an article on this style of view ...
4
votes
1
answer
2k
views
multiple inheritance in c++ to implement different interfaces
I am working on a finite element (FE) code and want to provide multiple material models (20+). In FE applications, the computational domain is subdivided into a set of geometrically simple elements, e....
4
votes
2
answers
428
views
Animal, Dog, and IDangerous - Using interfaces and inheritance with C#
I'm quite new to object-oriented C#. I wanted to test my knowledge by creating a Dog/Animal classes. I also tried to implement ...
2
votes
1
answer
328
views
PHP Laravel Order generation Custom Class
Here is a custom class I use to handle different types of orders in Laravel. This question includes the code regarding Order Type A. I want to know whether I can simplify the code. I have different ...
32
votes
5
answers
5k
views
Chess game for my students
I teach programming, and I currently teach my class about inheritance, abstract classes, and mixins.
I wrote this code as an example, and I want to be sure it is as good as possible before I release ...
4
votes
1
answer
3k
views
OpenGL Mesh Class
I've written a simple mesh class. The purpose of it is to build a mesh, draw it to the screen, and provide some means by which the mesh can be transformed/scaled, etc. This was done with GLAD, GLFW, ...
-2
votes
2
answers
120
views
Multiple inheritance of class broken up into modules [closed]
I have a class Main that uses fn(cls, ...) methods from several modules; they're used exclusively by ...
2
votes
2
answers
134
views
PreserveIds using inheritance id db auto incrementing
I am working on this project where I like to PreserveIds once inserted into the database. The id are auto incrementing and I return them once the data in inserted. I like to know if there is a better ...
0
votes
1
answer
120
views
Inheritance with Singletons [closed]
The problem / background
I have a project, BusinessProject, that currently stores some static data in memory using the Singleton pattern - we'll call this class ...
1
vote
4
answers
2k
views
Exercise: Design a Stack
Exercise: Design a Stack
A Stack is a data structure for storing a list of elements in a LIFO
(last in, first out) fashion. Design a class called Stack with three
methods.
...
5
votes
1
answer
809
views
Strategy pattern in C++ - the Duck simulator
I'm studying design patterns from Head First Design Patterns and, in order to get confident, I plan to implement the each pattern in C++ after studying the corresponding chapter.
As regards the ...
2
votes
1
answer
117
views
Dynamic module import in a class hierarchy
I have two python libraries, let's call them lib and extended_lib, that provide a very similar public API. To be more specific, <...
2
votes
1
answer
207
views
Read data from file: better approach using OOP
Suggestions to better understand when and how is convenient to use OPP.
This question is a follow-up question on this post.
I have a script that reads an input file. In time, the script may be ...
1
vote
1
answer
194
views
OOP paradigm in python - Extend class functionalities
I am a novice of Python and I am trying to understand how to use OOP paradigm to improve my scripts. My scripts usually read some data from a formatted csv file and perform some numerical analysis. ...
-1
votes
1
answer
390
views
abstract base classes versus the curiously recurring template pattern [closed]
Background
Apologies for "burying the lead." The questions are in the next section.
In my application, the purpose of inheritance is to abstract away complicated logic in the base class template, so ...