polymorphism

How do I implement polymorphic arithmetic operators pythonicly?

I'm trying to create a class that will allow me to add/multiply/divide objects of the same class together or add/multiply numeric arguments to each member of the class So my class is for coordinates (I am aware there are great packages out there that do everything I want better than I could ever hope to on my own, but now I'm just curio...

Multiple Type Inheritance in Ada

Suppose I have the following: type blah is abstract tagged record element1 : integer; end record; type blah2 is abstract tagged record element2 : integer; end record; I'm hoping that it's possible that I can do something like this: type blah3 is abstract new blah1 and blah 2 with null record; So in theory I can now access blah3...

C++: How do I pass a container of derived classes to a function expecting a container of their base classes?

HI! Anyone know how I can make the line "chug(derlist);" in the code below work? #include <iostream> #include <list> using namespace std; class Base { public: virtual void chug() { cout << "Base chug\n"; } }; class Derived : public Base { public: virtual void chug() { cout << "Derived chug\n"; } void foo() { cout << "Der...

Polymorphism on ActiveRecord model

I have two models, say Product and Bundle. products table is related to product_prices table and bundles to bundle_prices (need to make these separations to support multiple currencies) Obviously both Product and Bundle share some similar methods like get_price I have make both Product and Bundle pointing to an abstract Class for this...

Polymorphism? Inheritance? How to do it?

EDIT: I know it is a little strange design, and so it is difficult to answer. It Is FlowChart diagram on the picture. Every class represents some type of component used in this flowChart. But now I made much more clearer solution of my problem. The question is no more actual.//end EDIT Hello, I have a small problem which I dont know how...

Does this type of polymorphism has special name? (One class implementing two or more interfaces)

Just for learn: Say we have: interface Musician { /* content skipped */ } interface Teacher { /* content skipped */ } interface Swimmer { /* content skipped */ } class Crack implements Musician, Teacher, Swimmer { /* implementation skipped */ } Crack me = new Crack (); So we have that Crack objects are "polifacetic" (many faces...

Is Method Overloading considered part of polymorphism?

Is Method Overloading considered part of polymorphism? Thank you very much. ...

How to have abstract and overriding constants in C# ?

Hi all, My code below won't compile. What am i doing wrong? I'm basically trying to have a public constant that is overridden in the base class. public abstract class MyBaseClass { public abstract const string bank = "???"; } public class SomeBankClass : MyBaseClass { public override const string bank = "Some Bank"; } Thanks as a...

Implementation question regarding base classes and derived classes.

I have a question regarding the best way to implement this. I'm going to describe my current implementation and how I seem to have painted myself into a corner: I have an abstract class called Package: public abstract class Package { protected String description; protected String packagingCode; protected Dimension dimension...

polymorphism relates inheritance

why polymorphism is dependent on inheritance? code example? ...

Generics and polymorphism

Hi guys... I need ans for this problem badly--- difference between generics and polymorphism using code examples. I know its related somthing to compile time or binding but i am not sure..please help ...

Emulating Dynamic Dispatch in C++ based on Template Parameters

This is heavily simplified for the sake of the question. Say I have a hierarchy: struct Base { virtual int precision() const = 0; }; template<int Precision> struct Derived : public Base { typedef Traits<Precision>::Type Type; Derived(Type data) : value(data) {} virtual int precision() const { return Precision; } ...

Where did the word "polymorphism" come from?

I've always wondered where the word polymorphism word came from. I know what polymorphism is and I use it of course, but I just don't understand why this technique is called polymorphism. Note that I'm not a native English speaker, and I will thank you if you'll use simple English in your answers. ...

How to pass multiple different records (not class due to delphi limitations) to a function?

Hi to all. I have a number of records I cannot convert to classes due to Delphi limitation (all of them uses class operators to implement comparisons). But I have to pass to store them in a class not knowing which record type I'm using. Something like this: type R1 = record begin x :Mytype; class operator Equal(a,b:R1) end; type ...

Virtual functions and polymorphism

Suppose I have this: class A { public: virtual int hello(A a); }; class B : public A { public: int hello(B b){ bla bla }; }; So, A it's an abstract class. 1)In the class B, I'm defining a method that its suppose overrides the A class. But the parameter it's slightly different. I'm not sure about this, is this correct? ...

How do I add my own custom attributes to existing built-in Python types? Like a string?

I want to do something like this... def helloWorld(): print "Hello world!" string.helloWorld = helloWorld "foo".helloWorld() Which would print out "Hello world!" ...

Polymorphic call

I am new to java, I have seen in the code at many places where my seniors have declared as List myList = new ArrayList(); (option1) Instead of ArrayList myList = new ArrayList(); (option2) Can you please tell me why people use Option1, is there any advantages? If we use option2, do we miss out any advantages or features? ...

Polymorphism and c#

Here one more basic question asked in MS interview recently class A { public virtual void Method1(){} public void Method2() { Method1(); } } class B:A { public override void Method1() { } } class main { A obk = new B(); obk.Method2(); } So which function gets called? Sorry for the typos. ...

Java - problems with polymorphism

I have a book class, then a novel- and a science book class that extend the book class. I made an ArrayList using the book class, then inserted the novels and the science books into that. Now I'm trying to iterate through the ArrayList to count how many novels are there. How can I tell? Would love to see some examples of this! I've bee...

OO Design - polymorphism - how to design for handing streams of different file types

I've little experience with advanced OO practices, and I want to design this properly as an exercise. I'm thinking of implementing the following, and I'm asking if I'm going about this the right way. I have a class PImage that holds the raw data and some information I need for an image file. Its header is currently something like this: ...