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

4
votes
1answer
54 views

Initializing characters in a visual novel game

I am making a visual novel game and I was wondering is there a better way of setting character attributes and initializing than the way that I have done down below. As you can see I did an abstract ...
8
votes
1answer
101 views

Accessing the Stack Exchange API

Part of a project I'm getting started on requires access to the Stack Exchange API for certain data, as a result I built a .NET implementation to interact with it. The implementation is pretty ...
0
votes
2answers
80 views
6
votes
2answers
163 views

Dependency problem in C#, through polymorphism, and appropriate design pattern

I'm currently working on a project which involves EntityFramework with a (very) rich model (lots of inheritance). I'm currently facing a problem, quite interesting in my opinion. My model is ...
4
votes
1answer
75 views

Calculating a postfix expression

I've got the following code in my calculator project: ...
1
vote
0answers
46 views

Find the appropriate transformer for an abstract value

I want to get rid of the following code duplication within the MyFacadeBean. Consider the following situation: ...
5
votes
1answer
52 views

Polymorphic TLV serialization

Inspired by this question I decided to write an alternative that uses polymorhphism and a Factory pattern. The code works for the subset of implemented types, namely ...
2
votes
3answers
147 views

Polymorphically processing 2 & 3 dimensional objects

It seems there are a lot of "empty containers" (I do not know the correct, technical term) with regards to multiple levels of abstract classes and functional interfaces with little or no code. Is ...
2
votes
1answer
120 views

Sorting polymorphic classes

I'm learning from "Jumping into C++" by Alex Allain (sample chapter and TOC) and solved the first problem in Chapter 26 "Inheritance and Polymorphism". I'm especially concerned about my use of ...
3
votes
1answer
529 views

Check if JavaScript input is empty?

Having a general utility function to see if the input is empty makes sense to me. Empty means different things depends on the type. Just spent ~5 minutes writing this one up, so I'm sure it's missing ...
6
votes
2answers
456 views

Google reCAPTCHA Validator: Iteration II

This is a follow-up to the other post I made (less than an hour ago) about my Google reCAPTCHA C# implementation: Google reCAPTCHA Validator This adds support for error messages, so that you can ...
3
votes
1answer
163 views

Google reCAPTCHA Validator

This entire class came out of a chat discussion, and I'm curious on how it looks. (This is like literally 30 minutes of development time.) The idea is to allow very easy, quick implementations of ...
7
votes
3answers
162 views

Implementing Dynamic Network Message Handling (Part II)

This is an iterative review request of this other question I posted. As a follow up to that previous question, I changed the pattern completely and I went to an events-based approach, which might be ...
12
votes
2answers
187 views

Implementing Dynamic Network Message Handling

I'm trying to handle network messages in a dynamic, and effective way, though I feel I've overthought it again. As of now, I have a very structured approach, but it feels as if it's a lot of overhead ...
7
votes
1answer
227 views

Conversion calculator using polymorphism and Swing

This is my first attempt at a program (outside of school) and I was trying to implement and learn polymorphism on a conversion calculator for volumes and weights. I found myself using long ...
2
votes
1answer
64 views

Polymorphic components for graphics and program state

I asked this question on StackOverflow, got some answers, most notably a link to this one, and basing on that I've implemented this: ...
2
votes
0answers
281 views

Efficient compile-time directed graph

During my research in Rigid Body Dynamics, (where Contact Graphs are used to solve the contact problem) I came across the question if it is possible to define at compile time a directed graph (class) ...
2
votes
1answer
127 views

Vehicle Running Cost calculator

I'm making a road tax data calculator/parser for practice. I do this because I want to learn more about OOP and arrays with its functionality. On my previous post, i made this same application but ...
7
votes
1answer
130 views

Polymorphic animals speak their name and make a noise

I'm new to GNU Smalltalk. I'd like to port a script I've written in Ruby, Scala, CoffeeScript, and several others. It's the one I use to try to learn the classic OOP concepts of abstract classes, ...
3
votes
1answer
444 views

Text-based Tetris game with CRTP - follow-up

Previous question: Text-based Tetris game - follow-up - final Summary of improvements: Implementation of a Drawable class Separate functionality, input moves to ...
4
votes
2answers
306 views

Inserting and displaying books

I'm trying to write a program where you can insert and display some books (without using a database). For doing this, I use three classes: Book - is the base ...
8
votes
1answer
230 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: ...
6
votes
1answer
216 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
185 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
60 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 ...
7
votes
2answers
326 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
167 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 ...
7
votes
1answer
898 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 ...
8
votes
1answer
878 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
224 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 ...
9
votes
1answer
4k 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: ...
10
votes
6answers
2k views

Fluent interface and polymorphism for building a scene with shapes

I would like to improve the interfaces of some polymorphic classes going from positional to named parameters and I came up with the fluent interface. The following is the most clean, compact and ...
5
votes
2answers
93 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
478 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
1k 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
117 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: ...
3
votes
1answer
14k views

Very simple events implementation

I've been thinking about implementing events and wrote some abstract code: ...
3
votes
2answers
366 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
361 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
2k 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
733 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
691 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 ...
11
votes
11answers
1k 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 ...