Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

Questions tagged [polymorphism]

In computer science, polymorphism is a programming language feature that allows values of different data types to be handled using a uniform interface.

Filter by
Sorted by
Tagged with
4 votes
0 answers
103 views

As noted by @TobySpeight in his answer to Polymorphic data models that save data to MySQL and restore data from MySQL the test code should also be reviewed. His ...
pacmaninbw's user avatar
  • 26.2k
4 votes
2 answers
142 views

This is a follow up question to Inserting and retrieving data MySql Database access in C++ using Boost::ASIO and Boost::MySQL. I have reduced the amount of code to be reviewed by presenting only one ...
pacmaninbw's user avatar
  • 26.2k
7 votes
1 answer
641 views

There sometimes is a desire to have access to the base class of a polymorphic object without wanting the overhead of dynamic allocation, see for example this question. For a more value-like way of ...
G. Sliepen's user avatar
  • 69.5k
7 votes
3 answers
384 views

The idea of the following is to adapt a hierarchy of polymorphic classes DerivedX to std::variant without modification to ...
user avatar
4 votes
1 answer
126 views

The Design Patterns book chapter 3 about Creational Patterns starts with a maze game. They use the maze as an example throughout the chapter and instead of rooms they have also things like enchanted ...
elehtine's user avatar
  • 165
1 vote
0 answers
160 views

Second revision of the original post: Function overloading / dynamic dispatch for Python TL;DR: Improved version of this library[^1] based on previous reviews and criticism. It provides runtime ...
HernanATN's user avatar
  • 369
8 votes
2 answers
997 views

I am following the book crafting interpreters by Robert Nystrom using C++. In the book we use an Expr base class to describe expressions in the language lox. ...
Featherball's user avatar
5 votes
2 answers
1k views

UPDATE: Second revision on separate post. Runtime function overloading / dynamic dispatch for Python (2nd revision) When I first started using Python I had a rough time dealing with some of it's ...
HernanATN's user avatar
  • 369
6 votes
2 answers
792 views

Any comments/suggestions on this design? I just want to hold onto an ordered collection of messages. Each message can be one of several types. I'm using some code analogous to this currently in a ...
Taylor's user avatar
  • 303
-2 votes
1 answer
116 views

I found an example using std::variant to provide compile time polymorphism as a possible optimisation to runtime polymorphism in 'Software Architecture Using C++', https://github.com/PacktPublishing/...
arcomber's user avatar
  • 2,531
2 votes
2 answers
177 views

I'm creating a cache system for an object (Mesh) that is expensive to create. A Mesh can be created using a small amount of ...
Joshua Hyatt's user avatar
2 votes
1 answer
307 views

I'm writing software which allows a user to view data in a number of different formats, and they can switch between formats at any time. I'm wondering if there's a better way to do this than switching ...
djurgen's user avatar
  • 23
4 votes
1 answer
116 views

I have a Python logistic project that implements several shipping APIs using class inheritance. Each of those classes must do three things: Fire requests to each endpoint with the proper parameters ...
João Santos's user avatar
1 vote
1 answer
156 views

Annoyed at the tension between good software design principles that require well-defined delimitations between interface and implementations, and the requirements for critical code to run fast, which ...
lurscher's user avatar
  • 151
2 votes
1 answer
178 views

I have created a template class Gallery which is intended to be used as a container for objects. I used a private member of type...
Shwalala's user avatar
1 vote
1 answer
200 views

I am creating a .NET Framework MVC EF application for PC components. I wanted to make full use of inheritance, polymorphism and generic repository pattern - but was wondering if my initial design ...
Shaun Falconer's user avatar
4 votes
4 answers
3k views

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 ...
apex2022's user avatar
  • 161
0 votes
1 answer
96 views

I have a medium sized project that uses a class hierarchy that essentially boils down to: ...
MatG's user avatar
  • 149
3 votes
2 answers
10k views

Since writing your own C++ game engine seems to be really popular these days (seriously just look at the amount of people presenting their WIPs on YouTube) I figured I'd try it myself. My mental model ...
TheBeautifulOrc's user avatar
4 votes
1 answer
801 views

This is my attempt of implementing an efficient, cache-friendly, vector for polymorphic objects. From now on I will refer to "virtual functions" as functions which are dependent on an object'...
SomeProgrammer's user avatar
4 votes
2 answers
428 views

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 ...
tommy99's user avatar
  • 103
3 votes
2 answers
1k views

I am asking this, because after studying I am confused that it is necessary to declare base class object, then declare derived class object and then store reference of derived class object in base ...
BilalMohib's user avatar
3 votes
0 answers
1k views

> Exercise 1: Design a database connection To access a database, we need to open a connection to it first and close it once our job is done. Connecting to a database depends on the type of the ...
Milliorn's user avatar
  • 610
3 votes
1 answer
121 views

Introduction I am developing a dynamical system simulation/animation framework, which provides three abstract base classes, DynamicalSystem, ...
Richard Mace's user avatar
6 votes
3 answers
2k views

The following method is used to add objects to a polymorphic ArrayList from a file. It reads lines from the file, and based on a specific line which denotes the ...
Gherkin in God mode's user avatar
5 votes
1 answer
246 views

This is a follow up to this question Code incorporates Mathieu's comments and it works. As some parts of the review left some code to my knowledge, I ask for another review to see if I implemented ...
Ricardo Diaz's user avatar
5 votes
1 answer
304 views

I want to manage the Excel Styles in a more flexible way with bulk actions and at the same time improve my newly acquired OOP concepts. Objectives: Load the current Styles list (name and type=builtin ...
Ricardo Diaz's user avatar
3 votes
2 answers
806 views

I'm currently learning C by working on my first project. It's a calculator with a parser that transforms input into an operator tree. These trees consist of nodes of different types: Operators (inner ...
PhilippHochmann's user avatar
9 votes
2 answers
1k views

There is a basic difference in the way C++ manages the deleter for std::unique_ptr and std::shared_ptr, mainly for allowing ...
Amir Kirsh's user avatar
1 vote
1 answer
2k views

[Posted yesterday on Software Engineering, but was apparently "disappeared"...maybe better here] Background: I am just starting to get my head around the idea of separating the domain model from the ...
S'pht'Kr's user avatar
  • 119
4 votes
2 answers
986 views

Sometimes I use std::unique_ptr<BaseClass> when all I really want is polymorphism. For fun, I made this container that skips the heap allocation. The ...
sudo rm -rf slash's user avatar
9 votes
1 answer
2k views

Some time ago I implemented dynamic_array and posted it on Code Review. It used std::function internally for type erasure. This ...
L. F.'s user avatar
  • 9,715
2 votes
1 answer
1k views

GitHub GitHub if it's easier I'm in the process of doing a training course in C#. I've just gone over covering Polymorphic OOP / composition over inheritance etc... The latest exercise I completed ...
Webbarr's user avatar
  • 323
1 vote
1 answer
261 views

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 ...
Lin's user avatar
  • 357
4 votes
2 answers
447 views

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 ...
asaf92's user avatar
  • 231
2 votes
2 answers
545 views

I'm trying to implement equality for all types that share same base. Consider std::vector<unique_ptr<Shape>> and that we want to check if a certain ...
Amir Kirsh's user avatar
2 votes
1 answer
206 views

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 ...
Sebastian's user avatar
  • 143
6 votes
1 answer
2k views

Handling abstract types in json.net can be sometimes challenging because it requires a very long and complex syntax like: ...
t3chb0t's user avatar
  • 44.7k
2 votes
0 answers
97 views

In a ray tracing project that I'm trying to make compile-time (constexpr) for fun and challenge, I've run into a bit of an issue: I have an object (intersection) that needs to refer to one of a group ...
Sebastian's user avatar
  • 143
3 votes
1 answer
2k views

I'm implementing Curiously Recurring Template Pattern(CRTP) in Java as follows. The Interface: ...
Nimalan's user avatar
  • 33
9 votes
2 answers
1k views

A while ago a tricky C++ interview question came across to me, and ever since I could not tell what I did wrong. Create a base class named “Shape” with a method to return the area of the shape. ...
Caiwan's user avatar
  • 165
3 votes
1 answer
708 views

Motivation As an exercise, I wanted to try implementing function overloading in Python 3, i.e. to implement a way of defining multiple functions with the same name and then calling the appropriate ...
igal's user avatar
  • 391
4 votes
3 answers
2k views

I would be very grateful to get some thoughts on this toy-implementation of a trie that I wrote to practice my C++. Some questions I have: Is my create member ...
Reid Hayes's user avatar
0 votes
1 answer
166 views

I did the following Excercise: simulate single inheritance in C. Let each "base class" contain a pointer to an array of pointers to functions (to simulate virtual functions as freestanding ...
Sandro4912's user avatar
  • 3,152
10 votes
1 answer
5k views

I have an abstract class which acts as in interface for a variety of physical models providing Electric/Magnetic Fields as the result of a number of phenomena. I'm wondering if how I've done it is a ...
TomAdo's user avatar
  • 103
2 votes
0 answers
257 views

Task You should create an abstract Shape class that contains the stuff that would be similar across all shapes, and change Line and Rectangle so that they extend Shape. Then, in the DrawingModel ...
Susan's user avatar
  • 37
2 votes
0 answers
643 views

I've implemented a simple polymorphic structure, which looks a bit ugly and I'm afraid I am missing an idiomatic way of doing it. To describe briefly what I'm trying to achieve here: I would like to ...
Stormherz's user avatar
  • 121
5 votes
2 answers
683 views

I've studied and worked a lot on the subject for a month or two to get closer to the concept in a cleaner way, i.e. no virtual tables and no bunch of functions with prefixes etc. and most importantly ...
App2015's user avatar
  • 191
6 votes
1 answer
3k views

I tried to implement a simple signal&slots mechanism for some DSP software that runs on embedded Linux. I would like if somebody can review this code and give me some guidelines. Any review and ...
Nenad's user avatar
  • 63
0 votes
1 answer
5k views

I am writing Vehicle - Components - Car relationship. I have to separate cars that use the diesel, petrol and electric engines because each of them produce their own results (but methods of each are ...
Desna456's user avatar