polymorphism

Hiding inherited members in C#

I'm looking for some way to effectively hide inherited members. I have a library of classes which inherit from common base classes. Some of the more recent descendant classes inherit dependency properties which have become vestigial and can be a little confusing when using intellisense or using the classes in a visual designer. These ...

Inheritance and Polymorphism - Ease of use vs Purity

In a project our team is using object lists to perform mass operations on sets of data that should all be processed in a similar way. In particular, different objects would ideally act the same, which would be very easily achieved with polymorphism. The problem I have with it is that inheritance implies the is a relationship, rather th...

Expression Evaluation and Tree Walking using polymorphism? (ala Steve Yegge)

This morning, I was reading Steve Yegge's: When Polymorphism Fails, when I came across a question that a co-worker of his used to ask potential employees when they came for their interview at Amazon. As an example of polymorphism in action, let's look at the classic "eval" interview question, which (as far as I know) was brough...

Can I prevent an inherited virtual method from being overridden in subclasses?

I have some classes layed out like this class A { public virtual void Render() { } } class B : A { public override void Render() { // Prepare the object for rendering SpecialRender(); // Do some cleanup } protected virtual void SpecialRender() { } } class C : B { protected...

Reintroducing functions in Delphi

Does anyone know what the motivation was for having the reintroduce keyword in Delphi? If you have a child class that contains a function with the same name as a virtual function in the parent class and it is not declared with the override modifier then it is a compile error. Adding the reintroduce modifier in such situations fixes the...

At as deep of a level as possible, how are virtual functions implemented?

We all know what virtual functions are in C++, but how are they implemented at a deep level? Can the vtable be modified or even directly accessed at runtime? Does the vtable exist for all classes, or only those that have at least one virtual function? Do abstract classes simply have a NULL for the function pointer of at least one ent...

Where do "pure virtual function call" crashes come from?

I sometimes notice programs that crash on my computer with the error: "pure virtual function call". How do these programs even compile when an object cannot be created of an abstract class? ...

What's the difference between Polymorphism and Multiple Dispatch?

...or are they the same thing? I notice that each has its own Wikipedia entry: [1] [2], but I'm having trouble seeing how the concepts differ. Edit: And how does Overloading fit into all this? ...

How do you do polymorphism in Ruby?

In C#, I can do this: class Program { static void Main(string[] args) { List<Animal> animals = new List<Animal>(); animals.Add(new Dog()); animals.Add(new Cat()); foreach (Animal a in animals) { Console.WriteLine(a.MakeNoise()); a.Sleep(); } } } publi...

C++ alternatives to void* pointers (that isn't templates)

It looks like I had a fundamental misunderstanding about C++ :< I like the polymorphic container solution. Thank you SO, for bringing that to my attention :) So, we have a need to create a relatively generic container type object. It also happens to encapsulate some business related logic. However, we need to store essentially arbitr...

conditional logic based on type.

Given: interface I { } class B: I { } class C: I { } class A { public void Method(B arg) { } public void Method(C arg) { } public void Method(I arg) { // THIS is the method I want to simplify. if (I is B) { this.Method(arg as B); } else if (I is C) ...

Polymorphism vs Inheritance (example problem case)

I am still trying to wrap my head around design patterns and for the second time I'm coming up against the same problem that seems to be crying out for a pattern solution. I have an accounts system with multiple account types. We have restaurant, hotel, service_provider, and consumer account types. Im sure there will be more business a...

How does the C++ compiler know which implementation of a virtual function to call?

Here is an example of polymorphism from http://www.cplusplus.com/doc/tutorial/polymorphism.html (edited for readability): // abstract base class #include <iostream> using namespace std; class Polygon { protected: int width; int height; public: void set_values(int a, int b) { width = a; height = b; } ...

XSD and polymorphism

I am kinda repeating this question bit the 1st time it was asked incorrectly. I have this: <xsd:complexType name="A"> <xsd:sequence> <xsd:element name="options" type="options"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="B"> <xsd:complexContent> <xsd:element name="options" t...

Try to describe polymorphism as easy as you can

we can find a lot of information about the subject on the internet and books http://en.wikipedia.org/wiki/Type_polymorphism but lets try to make it as simple as we can . ...

Polymorphic functors in std::for_each

I'm trying to use stl algorithm for_each without proliferating templates throughout my code. std::for_each wants to instantiate MyFunctor class by value, but it can't since its abstract. I've created a functor adapter class which passes a pointer around and then derefernces it when appropriate. My Question: Does the STL or Boost alrea...

Do polymorphism or conditionals promote better design?

I recently stumbled across this entry in the google testing blog about guidelines for writing more testable code. I was in agreement with the author until this point: Favor polymorphism over conditionals: If you see a switch statement you should think polymorphisms. If you see the same if condition repeated in many places in your cl...

python properties and inheritance

I have a base class with a property which (the get method) I want to overwrite in the subclass. My first thought was something like: class Foo(object): def _get_age(self): return 11 age = property(_get_age) class Bar(Foo): def _get_age(self): return 44 This does not work (subclass bar.age returns 11). I ...

Polymorphism in JAX-RPC web services

I have a JAX-RPC (Java) web service that needs to return a complex polymorphic value. To be more specific, the class structure is something like this: abstract class Child { } class Question extends Child { private String name; // other fields, getters, and setters } class Section extends Child { private String label; ...

Return type polymorphism in C-like languages

Why don't we see C-like languages that allow for callables with polymorphism in the return type? I could see how the additional type inference would be a hurdle, but we have plenty of languages with full-fledged type inference systems (that work for varying levels of "work"). Edit: By return type polymorphism I mean overloading the func...