polymorphism

Model and controller design approach for polymorphic assocation

Below I have outlined the structure of a polymorphic association. In VacationsController I put some comments inline describing my current issue. However, I wanted to post this to see if my whole approach here is a little off. You can see in business_vacations_controller and staff_vacations_controller that I've had to make 'getters' for ...

Undefined reference to enum

I'm getting this error message from my compiler: undefined reference to `Pawn::Pawn(Piece::Color)' This occurs when I do this: // board[][] contains pointers to Piece objects board[0][0] = new Pawn(Piece::BLACK); Here's part of the Pawn class: // Includes... #include "piece.h" // Includes... class Pawn : public Piece { public: ...

using "new this.GetType()" in a base class to instantiate a derived class

I have a base class A and classes B and C are derived from it. A is an abstract class, and all three classes have a constructor that takes 2 arguments. Is it possible to make a method in the base class A like this: A* clone() const { return new this.GetType(value1, value2); } and if the current object whose clone()-function is bei...

Can child templates stored in a base class array, use an overloaded virtual function?

In hope to simplify a homework problem dealing with inheritance, I thought it might be better to use polymorphism to accomplish the task. It isn't required, but makes much more sense if possible. I am, however, getting symbol errors making it work as I thought it should or just the base class definition is called. I want the overloade...

Cleanly duplicate an instance of a baseclass or subclass in C++?

In the trivial example inheritance hierarchy: class Food { virtual ~Food(); }; class Fruit : public Food { virtual ~Fruit(); }; class Apple: public Fruit { virtual ~Apple(); } class Vegetable: public Food { virtual ~Vegetable(); } I wish to create a method that can clone an object from its subclass or baseclass inst...

Polymorphism broken when changing web site project to web application project

Greetings, I just converted an ASP.NET Web Site Project to a Web Application Project in VS 2010. After I run the application though it seems that my class polymorphism broke. I don't have a clue as to why this could occur. So in the following code when I call base.OnLoad(e) I am getting errors in the base class because the variable m...

Json to pojo unmarshaler with polymorph classes for android

Hello, I am having a problem with rest and android, the problem is I have a transport object in example a class Human, which is extended by Male and Female, I want to use json as transport for the human object. if I use standard serialized objects, i would usually do if(human instanceof Male.class){} else if(human instance of Female...

Why is Java's polymorphism failing to catch the right method when choosing between object and vector?

I have two similar methods. One is intended to handle objects, the other vectors: @SuppressWarnings("unused") private void printRows(PrintWriter out, Vector<?> dataOb, String[] columns, String[] columnType, Hashtable<?, ?> columnAccessors, String trOptions, String tdOptions) throws ServletException { ...

Is there a Haskell equivalent of OOP's abstract classes, using algebraic data types or polymorphism?

In Haskell, is it possible to write a function with a signature that can accept two different (although similar) data types, and operate differently depending on what type is passed in? An example might make my question clearer. If I have a function named myFunction, and two types named MyTypeA and MyTypeB, can I define myFunction so th...

C# Generics Inheritance

I have the following class public class AccountingBase<TItemType> where TItemType : AccountingItemBase And in my AccountingItemBase i have the following property: public virtual AccountingBase<AccountingItemBase> Parent { get; set; } in my AccountingBase, I am trying to do the following item.Parent = this; Logically this should ...

How to define polymorphism in JPA

Hi, there is a situation. For example, I am designing simple blog. There are articles and photographies. Users can add their comment to both of them. So when I write it in Java, it looks like this: public interface Commentable { ... } public class Article implements Commentable { ... } public class Photo implements Commentable { ... ...

Type polymorphism in scala

I'm just getting started with Scala and something which I think should be easy is hard to figure out. I am trying to implement the following function: def square(x:Int):Int = { x * x } This works just fine, but if I want to try to make this function work for any kind of number I would like to be able to do the following: def square[T ...

Overriding default accessor method across different classloaders breaks polymorphism

Hello. I come across to a strange behavior while trying to override a method with default accessor (ex: void run()). According to Java spec, a class can use or override default members of base class if classes belongs to the same package. Everything works correctly while all classes loaded from the same classloader. But if I try to load...