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

learn more… | top users | synonyms

5
votes
0answers
58 views

Transformation of abstract models

In one of my recent projects I faced the problem of transforming an abstract class into another abstract class. The classes were structured like this and are part of an api for questionnaires: ...
5
votes
0answers
94 views

Image Processing Pipeline

I'm currently toying around with some Computer Vision algorithms and always wanted to learn more about templates, so I came up with the idea to build a templated Image Processing Pipeline. I want the ...
8
votes
3answers
150 views

Single inheritance polymorphism

I am learning about polymorphism in C++ and decided to implement an example. Is there anything I need to fix in my code? This compiles and runs. ...
3
votes
1answer
56 views

Type dispatch based on runtime value

Suppose we're implementing an interpreter for the bytecode of some stack machine. Let every element of the stack be a Word8, and let the stack be represented by a ...
6
votes
2answers
134 views

Interface-based polymorphic collection

Here is a small C++11 utility collection to store any object that satisfies a given interface. Only the basic concepts are provided, I did not try to create a full collection: ...
5
votes
1answer
123 views

Changing the type of an object inside a method?

First off, this is not my code. I'm curious what everyone thinks about changing the type of an object inside of a method then modifying the properties of the cast type. I wanted to use composition to ...
5
votes
1answer
276 views

Polymorphic (owned) reference wrapper for class hierarchies

Rationale: I often have the requirement to own object instances, while preserving polymorphic behavior (i.e. own the object and hold it by pointer, or reference). This is usually expressed as a ...
4
votes
0answers
117 views

Static Multilevel Inheritance with CRTP (Fast Intrusive Pointers)

I wanted to have a way to be able to static_cast to the proper derived type pointer of a base class to simulate a virtual call. Here the virtual call is for a ...
2
votes
1answer
87 views

Is this a meaningful Intrusive Pointer Class?

Is this intrusive pointer implementation correct? I tried to use the CRTP Pattern to avoid a virtual destructor in my class ReferenceCounting which provides the ...
7
votes
1answer
826 views

Variadic templates and pointers to member functions to achieve a named-parameters interface in C++

I studied a bit and packed all the suggestions that I received here: Fluent interface and polymorphism and I came up with this: ...
7
votes
6answers
736 views

Fluent interface and polymorphism

EDIT: For further improvements see the related question: Variadic templates and pointers to member functions to achieve a named-parameters interface in C++ I would like to improve the interfaces of ...
5
votes
2answers
78 views

Avoiding casts in abstract types

I asked this question on Stack Overflow and in the comments someone had this to say. In a proper design, you should almost never have to do a dynamic_cast, even if it's hidden inside some nice ...
7
votes
1answer
163 views

Concept based polymorphism

I have a concept based polymorphism example listed below. I allow the user to provide any type that implements the draw method and then I add it into a vector of ...
0
votes
1answer
541 views

Understanding polymorphism in Python

I feel like I don't understand how polymorphism works in Python. Here is something I put together. ...
2
votes
2answers
104 views

designing application using polymorphism

I have created a polymorphic system, but I don't know whether this is the correct way of doing it. Am I abusing Polymorphism here? Here is the code: ...
1
vote
1answer
1k views

Very simple events implementation

I've been thinking about implementing events and wrote some abstract code: ...
3
votes
2answers
210 views

Null Object pattern with simple class hierarchy

I have a simple two-class hierarchy to represent U.S. ZIP (12345) and ZIP+4 (12345-1234) codes. To allow clients to allow both types for a field/parameter or restrict it to one type or the other, the ...
3
votes
1answer
166 views

Hardware resource Open/Close methods

So I'm making a program that is a serial port wedge. In other words I want it to listen to a serial port. If data comes in, wait a given amount of time, then play a sound and finally send the data ...
1
vote
4answers
319 views

Understanding interface with animal classes

I made this small program to demonstrate to myself an example of interface. I wanted to confirm whether it is correct and if there is anything more I should know about interfaces other than the ...
0
votes
1answer
272 views

Is this the proper way to find the subclass of a polymorphic superclass?

I came across polymorphism in the book that I'm reading and decided to do a little experiment. Essentially what I did was to create a base class called Asset and ...
3
votes
2answers
342 views

Refactoring to a polymorphic association

I'm running into an issue while playing around with some models in a Rails app. Namely issues of the polymorphic variety. I think I may have solved it, more or less looking for an approval. I have ...
10
votes
11answers
914 views

Design dilemma: extensibility vs simplicity

Here is my problem abstracted to Bird classes. I know that number of Birds will increase on the future and new behaviors might ...