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
0 votes
1 answer
21 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, ...
user avatar
0 votes
0 answers
24 views

Two different JavaScript implementations of the observer pattern using class inheritance and concatenative inheritance

To practice design patterns and JavaScript, I'm implementing the observer pattern in two different ways: One implementation using class inheritance And another implementation using concatenative ...
user avatar
  • 729
0 votes
0 answers
35 views

Learning UML and OOP, trying to make a game in python. What do you think of this UML diagram?

I'm working on refactoring a simulation that i started writing in python / pygame. The gist is, there's buildings scattered around a map, and units carry items back and forth from said buildings. I ...
user avatar
  • 61
2 votes
1 answer
122 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: ...
user avatar
3 votes
0 answers
79 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 ...
user avatar
1 vote
0 answers
33 views

How was this python code analyze these classes with class diagram

Anyone please review my code and give some improvement suggestions. I wrote code but not to the best standards. I think this site give some valuable suggestions this code is for extracting xlsx or csv ...
user avatar
4 votes
4 answers
1k 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 ...
user avatar
1 vote
1 answer
107 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 ...
user avatar
-1 votes
2 answers
75 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 ...
user avatar
  • 9
1 vote
1 answer
223 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 ...
user avatar
  • 143
1 vote
1 answer
181 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). ...
user avatar
3 votes
2 answers
99 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 ...
user avatar
  • 73
0 votes
1 answer
34 views

Deduplicate << operator implementation on inheritance

I have the following working code: person.h ...
user avatar
3 votes
2 answers
111 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'...
user avatar
  • 33
0 votes
2 answers
415 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 ...
user avatar
5 votes
2 answers
414 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 ...
user avatar
  • 151
2 votes
0 answers
90 views

what should be the best approach to follow DRY principle here

My first component ...
user avatar
  • 129
2 votes
1 answer
105 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 ...
user avatar
2 votes
1 answer
145 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 ...
user avatar
5 votes
2 answers
139 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 ...
user avatar
  • 53
2 votes
1 answer
36 views

Colour-model classes using CRTP

I want to implement color space logic. So I started with creating some structs: ...
user avatar
3 votes
0 answers
978 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 ...
user avatar
4 votes
1 answer
340 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....
user avatar
4 votes
2 answers
166 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 ...
user avatar
  • 113
2 votes
1 answer
82 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 ...
user avatar
  • 47
31 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 ...
user avatar
  • 463
1 vote
0 answers
75 views

Inheritance Challenge 2 - Employees, Bosses and Trainees in C#

Inheritance Challenge 2 - Employees, Bosses and Trainees Create a main class with a Main Method, then a base class Employee with the properties Name, FirstName, Salary and the methods Work() and ...
user avatar
  • 620
3 votes
1 answer
1k 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, ...
user avatar
-1 votes
2 answers
73 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 ...
user avatar
2 votes
2 answers
78 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 ...
user avatar
  • 521
0 votes
1 answer
77 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 ...
user avatar
1 vote
4 answers
1k 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. ...
user avatar
  • 620
5 votes
1 answer
399 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 ...
user avatar
  • 497
2 votes
1 answer
45 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, <...
user avatar
2 votes
1 answer
87 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 ...
user avatar
  • 53
1 vote
1 answer
120 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. ...
user avatar
  • 53
-1 votes
1 answer
132 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 ...
user avatar
  • 177
1 vote
0 answers
34 views

Faster Google Spreadsheet access and direct use of Named Ranges for code readability

This object structure, that I think might be useful for a number of projects, attempts to: learn the use objects (classes are not available in Google Apps Script) and inheritance minimize calls to ...
user avatar
4 votes
2 answers
110 views

Human Jug and Glass

I am a beginner in Java. I have created this small project in Java with the inheritance concept. Here the Human will fill, pour and drink water. There are three classes: Glass, Jug and Human. Let me ...
user avatar
  • 143
0 votes
2 answers
715 views

Get the width and height of a shape as user input

I made this program to understand inheritance better. Now that I'm at this basic level it's not really a problem but I can see this coming in the future and so I'm asking what's the best method to ...
user avatar
1 vote
1 answer
61 views

Shift register library design

I am creating a small library for controlling bars of leds and have some doubts about my design. I have 2 basic entities in the design so far: BarService (and implementation) ...
user avatar
4 votes
1 answer
110 views

Using composition instead of inheritance and abstract classes

I have a tool that displays data in some format. For example, it can display a list of dogs in a CSV or JSON formats. In the code, I had a lot of places where I had to check the format and display ...
user avatar
  • 271
0 votes
1 answer
683 views

C++ linked list inheriting from node class

I am currently in between semesters at school and am using that time to improve on my knowledge of C++ classes by making a node class and a linked list class that inherits from the node class. There ...
user avatar
2 votes
0 answers
42 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 ...
user avatar
1 vote
1 answer
52 views

Using nullable properties in a base class for record selection in Table per Hierarchy

I want to be able to list every Transaction associated with a Client in date order. ...
user avatar
2 votes
1 answer
104 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 ...
user avatar
  • 289
2 votes
2 answers
150 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....
user avatar
  • 171
1 vote
0 answers
44 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 ...
user avatar
4 votes
0 answers
61 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 (...
user avatar
  • 61
5 votes
1 answer
102 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. ...
user avatar
  • 204

1
2 3 4 5
7