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
1 answer
56 views

Logistics project that implements several shipping APIs

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 ...
user avatar
1 vote
1 answer
50 views

One-time dynamic, many-time *almost* static type dispatch

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 ...
user avatar
  • 141
2 votes
1 answer
81 views

Gallery template class

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...
user avatar
0 votes
1 answer
52 views

Entity Framework - component shop using polymorphism and generic repository

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

Inquiring possible alternatives to custom hierarchy-aware smart pointer

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

C++: Event system for game engine

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 ...
user avatar
4 votes
1 answer
183 views

Efficient vector-like polymorphic container which retains type information

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'...
user avatar
1 vote
0 answers
17 views

Using (templated) function-scope static address as Unique ID [closed]

typedef const bool* const TypeID; template<typename> TypeID TypeIdOf() noexcept { static const bool idLoc(0); return &idLoc; } I'm using ...
user avatar
4 votes
2 answers
167 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
3 votes
1 answer
625 views

Banking system using polymorphism

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 ...
user avatar
3 votes
0 answers
603 views

POLYMORPHISM - Design a database connection and command

> 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 ...
user avatar
  • 620
3 votes
1 answer
69 views

Dynamical system animation framework

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

Supermarket Product Inventory Management with Polymorphic Product Types

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 ...
user avatar
5 votes
1 answer
140 views

Manage Excel Styles with VBA OOP Approach (Follow up)

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 ...
user avatar
5 votes
1 answer
142 views

Manage Excel Styles with VBA OOP Approach

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=...
user avatar
1 vote
0 answers
38 views

Generic car instantiating pattern to minimize GC

I'm facing the problem of needing to instantiate lots of cars, and I'd like to recycle the cars no longer used. Each one of my car types, which define how each car should be created, are treated as ...
user avatar
  • 11
3 votes
2 answers
406 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 ...
user avatar
5 votes
0 answers
719 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 ...
user avatar
1 vote
1 answer
890 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 ...
user avatar
  • 119
1 vote
0 answers
55 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 <...
user avatar
  • 111
4 votes
2 answers
621 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 ...
user avatar
9 votes
1 answer
898 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 ...
user avatar
  • 8,937
2 votes
1 answer
734 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 ...
user avatar
  • 323
0 votes
1 answer
152 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 ...
user avatar
  • 243
3 votes
2 answers
340 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 ...
user avatar
  • 221
2 votes
2 answers
279 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 ...
user avatar
2 votes
1 answer
154 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 ...
user avatar
  • 143
6 votes
1 answer
1k 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: ...
user avatar
  • 43.8k
2 votes
0 answers
54 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 ...
user avatar
  • 143
3 votes
1 answer
1k views

Curiously Recurring Template Pattern (CRTP) implementation

I'm implementing Curiously Recurring Template Pattern(CRTP) in Java as follows. The Interface: ...
user avatar
  • 33
9 votes
2 answers
674 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. ...
user avatar
  • 155
3 votes
1 answer
472 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 ...
user avatar
  • 361
4 votes
3 answers
2k 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 ...
user avatar
0 votes
1 answer
130 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 ...
user avatar
  • 2,976
10 votes
1 answer
4k 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 ...
user avatar
  • 103
2 votes
0 answers
210 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 ...
user avatar
  • 37
2 votes
0 answers
547 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 ...
user avatar
  • 121
5 votes
2 answers
622 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 ...
user avatar
  • 201
6 votes
1 answer
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 ...
user avatar
  • 63
0 votes
1 answer
4k 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 ...
user avatar
1 vote
2 answers
114 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: ...
user avatar
2 votes
0 answers
597 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 ...
user avatar
1 vote
1 answer
60 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 ...
user avatar
  • 113
3 votes
4 answers
426 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. ...
user avatar
  • 139
1 vote
2 answers
152 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 <...
user avatar
-2 votes
1 answer
168 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-...
user avatar
  • 5,920
-2 votes
1 answer
225 views

Parsing various types of message strings

Similar question MessageFormat: represents the various kinds of messages. (XML, JSON, ...
user avatar
  • 169
3 votes
0 answers
446 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: ...
user avatar
5 votes
2 answers
637 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 ...
user avatar