Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

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
3
votes
2answers
96 views

Implementation of tree with different node types and faux-polymorphism in C

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 ...
4
votes
0answers
49 views

Polymorphic deleter for unique_ptr

There is a basic difference in the way C++ manages the deleter for std::unique_ptr and std::shared_ptr, mainly for allowing ...
-1
votes
0answers
32 views

Searching for items in different objects and printing their names

The program gets a map of different lists of objects (DeploymentList and DaemonSetList). It runs over each of the lists and pass ...
0
votes
1answer
56 views

Builder pattern in C# supporting subclassing with nested classes [closed]

[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 ...
1
vote
0answers
54 views

Work around for querying type of derived class

I have an application where messages are collected and dispatched to various handlers. Messages are derived from the base class MessageBase, handlers derived from <...
3
votes
2answers
63 views

A polymorphic union in C++

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

A C++17 std::function implementation

Some time ago I implemented dynamic_array and posted it on Code Review. It used std::function internally for type erasure. This ...
2
votes
1answer
74 views

Polymorphic DBConnector class exercise

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 ...
0
votes
1answer
68 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
316 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
2answers
188 views

Polymorphic implementation for == with CRTP

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 ...
2
votes
1answer
82 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 ...
5
votes
1answer
627 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: ...
2
votes
0answers
50 views

Creating an array of distinct objects with an identical method that can be evaluated (mapped) at compile-time (constexpr)

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 ...
2
votes
1answer
474 views

Curiously Recurring Template Pattern (CRTP) implementation

I'm implementing Curiously Recurring Template Pattern(CRTP) in Java as follows. The Interface: ...
9
votes
2answers
260 views

Area calculator for shapes as an OOP interview test

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. ...
2
votes
0answers
245 views

Function overloading in Python

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 ...
4
votes
3answers
496 views

Simple trie class in C++

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 ...
0
votes
1answer
112 views

Drawing various types of shapes [closed]

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 ...
8
votes
1answer
1k views

CUDA/C++ Host/Device Polymorphic Class Implementation

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 ...
2
votes
0answers
95 views

Classes for shapes and development [closed]

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 ...
2
votes
0answers
287 views

Rust idiomatic way of polymorphic struct

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 ...
5
votes
2answers
614 views

Polymorphism with overrides and base calls simulating an employee

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 ...
6
votes
1answer
2k views

Simple implementation of signals and slots mechanism using templates

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 ...
0
votes
1answer
3k views

Vehicle, Components and Car relationship [closed]

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 ...
2
votes
2answers
112 views

C++ limiting a method for an rvalue caller, an expression evaluator example

There are many ways to implement a math expressions evaluator (I focus here just on the evaluator part, without any parsing). I want to explore a certain implementation to support the following main: ...
2
votes
0answers
459 views

Laravel polymorphic usage

I am fairly new to Laravel and have implemented a many to many polymorphic relationship to a model where you have two tables that act as polymorphic references one is for content (text information ...
1
vote
1answer
54 views

Separating logic per class and being able to use dependency injection

I use Laravel, but hopefully this doesn't matter. I have a user and user's state. Say, simple integer or a string. I want to run some logic depending on user state in my service class. So, the first ...
3
votes
4answers
229 views

Custom shapes objects using polymorphism in JavaScript

I have made the following example and want to know if it properly represents polymorphism in JavaScript. ...
1
vote
2answers
114 views

Increment object properties based on a particular subclass of an abstract class

I have a Composition object that contains 4 ArrayList objects, each of which contains objects of a particular subclass of my <...
-2
votes
1answer
161 views

Document Management Properties and Searching

This is the 'middle-ware' for a document management application. A document has properties which describe it, and allow users to search for it. The server will interact with the database, and the User-...
-2
votes
1answer
220 views

Parsing various types of message strings

Similar question MessageFormat: represents the various kinds of messages. (XML, JSON, ...
3
votes
0answers
323 views

Replacing dynamic polymorhism with static polymorphism in C++

Motivated due to the fact, that the avr-g++ places the vtables in RAM, I wrote a replacement using static polymorphy. Consider the following example: ...
5
votes
2answers
454 views

Stopwatch that uses the abstract factory design pattern

I have wrote code for a stopwatch that utilizes the abstract design pattern and would like to get some feedback on the code, so be as harsh as you can. Note: I used ...
1
vote
0answers
89 views

Watch that uses the abstract factory design pattern

I have wrote code for a Watch that utilizes the abstract design pattern and would like to get some feedback on the code, be as harsh as you can. Also, I would like ...
0
votes
1answer
597 views

Menu that utilizes the composite design pattern

I have made a menu that utilizes the composite design pattern and would like to get some feedback on the code, so be as harsh as you can. Menu.h: ...
7
votes
1answer
2k views

Python solution to Mars Rover

I'm still quite new to Python, but am loving the language (I come from a more strongly-typed language background..). A month or so ago I found the Mars Rover Challenge and attempted to solve it. I ...
-2
votes
1answer
2k views

C++ Erasing an object from vector of pointers

I am making this simple game in SFML and I have this vector of pointers std::vector<Brick*> bricks; which stores objects of class ...
5
votes
2answers
242 views

Free general e-book downloader

So I decided to expand a little one-off C# console program I wrote awhile ago to download the free e-book offered by Syncfusion, and decided to also do it for other free e-book publishers... like O'...
5
votes
1answer
1k views

Building a model-view-controller application in PHP

I've seen at least two recent PHP questions that would do well from a Model-View-Controller ('MVC' from here-on-out in this question) setup. Now, me, being the horrible person I am, I wanted to build ...
10
votes
2answers
194 views

There Was an Old Lady - generate lyrics to a cumulation song

This is a problem from exercism.io. View the repo here (contains full example of song). Problem statement: Generate the lyrics of the song 'I Know an Old Lady Who Swallowed a Fly'. While you ...
11
votes
1answer
172 views

Multiple similar manager classes for handling scroll lists

I am working on my first object-oriented programming project, written in C# for Unity. My code does what I want it to do, but I am wondering if there is a better way to do it. I think I am building ...
5
votes
2answers
485 views

99 Bottles of Beer using polymorphism

This was part of an exercise from exercism.io. If you fancy, view the repo here. Given problem statement: Write a program which produces the lyrics to that beloved classic, that field-trip ...
2
votes
2answers
86 views

Represent a person who has different roles for different offices

People have different types of roles depending on the office they are working at. For example, a person has two roles (cashier,cleaner) at OfficeMax and five roles(manager,security,etc) at OfficeLess. ...
3
votes
3answers
711 views

Models an assembly line

The gist of the code is that there's an assembly line of products, in this case Toy and Book, that get inspected by workers who then add them to a box. The box is then sent to someone who knows what ...
2
votes
2answers
1k views

Calculate area and perimeter for shapes: polygon, circle, rectangle and triangle - follow up

This is the new code after the changes suggested by @Cody Gray in the last question: Calculate area and perimeter for shapes: polygon, circle, rectangle and triangle This is my project on ...
8
votes
1answer
16k views

Calculate area and perimeter for shapes: polygon, circle, rectangle and triangle

This is my project on inheritance and polymorphism. I have the main file from my teacher and built the project base on it. My base class is Shape. ...
7
votes
2answers
149 views

C function to print arrays of arbitrary data type

C is naturally clumsy at polymorphism but I wanted to avoid duplication so I wrote this function. But I'm sure there are ways left to improve it. Please not that for brevity's sake not all data types ...
1
vote
0answers
97 views

Using polymorphic objects to represent parts of a deconstructed sentence

I am trying to make a chatbot using javascript by deconstructing a sentence into its intent by separating the Noun's Verb's, Adjectives, Durations's, Numbers etc... to construct a data query to try to ...
-1
votes
1answer
15k views

Calculate the area of different shapes using polymorphism (virtual and override methods)

I have written code to calculate the area of different shapes using polymorphism (virtual and override methods) and it is working as expected. Can anyone please review this and let me know how I can ...