Questions for polymorphism


Rails 3.2 Rendering Associated Models in Same Form

i'm working through Hartl. Ive got to the microposts section in Chapter 10, but instead of microposts I have introduced Hotels, and now I want to add them to a separate address model, like in this

Polymorphism for geometric forms

I am developing a small drawing application, with a little library of "complex" forms to be dragged and dropped.

How to mimic polymorphism in classes with template methods (c++)?

in the problem i am facing i need something which works more or less like a polymorphic class, but which would allow for virtual template methods.

How to get the integers 35 and 50 in the output of this program ?

I am really very new in C++ programming and its been only a month i started learning Object Oriented Programming and i was learning this program of inheritance and I am not getting the output i wan...

Polymorphic factory / getInstance() in Java

I'm aiming to create a set of objects, each of which has a unique identifier. If an object already exists with that identifier, I want to use the existing object. Otherwise I want to create a new o...

How should I cast for Java generic with multiple bounds?

Is it possible to cast an object in Java to a combined generic type?

should new behavior be introduced via composition or some other means?

I chose to expose some new behavior using composition vs. injecting a new object into my consumers code OR making the consumer provide their own implementation of this new behavior. Did I make a bad

How/when do I use a virtual destructor?

I'm currently writing a program with the following polymorphic hierarchy: Base: Multinumber. Derived: Pairs, Complex, Rational. Multinumber is a virtual class and is never instantiated.

Mongoid complex ploymorphic relationship

I would like to set up a set of relationships that look something like the code below

Convert derived class to base class

I'm trying to refresh my memory but can't find answers with Google.

Rails inheritance for classes of same behaviour but different attributes

I have been researching on the best approach for my problem which I originally had implemented as a single table inheritance but am deeply concerned about the scalability, as potentially will have

Rails polymorphic association representing existing has_many models

I'd like to create a 'timeline' feature for an existing Card model. The Card already has_many Notes and has_many Attachments. I'd like to be able to:

Send actual object type to overloaded function

So, please consider the following situation

Multiple Inheritance/Polymorphism Homework

I have a homework assignment coming up that I am a bit confused on. The assignment basically states that we are to use Multiple Inheritance/Polymorphism to make 21 classes in a hierarchical manner. I

Using inherited_resources for nested, polymorphic comments

I am new to using inherited resources and want to use it for

How to get an object with certain type using C# Linq?

I have Generic list holding root objects means I have:

How do you add images to an array?

I am stuck on a project because I have no clue how to store a picture into an array.

Java snippet output not understood, probably related to polymorphism

I was wondering why this bit of Java yields 2, and not 3 :

C++ - base implementation called through reference of derived?

Consider following code (minimal version):

Weird polymorphism c++?

Anyone can explain this weird bit in this line of code to me?

Extending a base class to a derived class

We have two classes BasicRace & AdvancedRace.

How does boost::serialization Archive::register_type work?

boost::serialization is able to serialize my polymorphic objects of their most-derived class even if these objects are pointed by a reference/pointer to the base class. This without needing virtual

Polymorphic methods not working on C# 4

I just stumbled over a very interesting problem. Giving the following code:

Avoid RTTI when dealing with pairs of objects

I saw a few questions about avoiding RTTI, but mine seems to be a bit more specific. Here is an example case:

Extensible ad hoc polymorphism? (C++11)

I need to implement a generic algorithm that can operate on a matrix regardless of its representation. It could be a C-style 2D array, a vector of vectors or an arbitrary user class (which does not

How can I get a model class from a string?

I have a Model called Todo.rb which has an attribute called "asset" which is a string. The string contains the names of Models such as Call, Email, etc.

Basic polymorphism/inheritance issues

I'm working with Java. I have done all of the research I could, but I could not find the answer to my question.There are certain parts of this code that I am not allowed to change and still fulfill...

Use a children method c++

I have those objects:

Method for getting polymorphic relationship table name in Rails. Meta-programming

I want to test if a Polymorphic child belongs to parent.

Pre-written main function for each base class

Is there a sensible way to do the following:

Polymorphic MVC Views

So I am making a registration page in ASP.NET MVC and theres a list of fields which changes depending on a number of conditions (taken from a database).

How to inherit a member function so that it always returns a reference to the derived instance?

I'm working on an iterator family, where all iterator classes X have X& operator++() {++x; return *this} in common, so it seems to be a good idea to place it in a common base class. Unfortunate...

Methods of summary() function

I'm using summary() on output of mle(stats4) function, its output belongs to class mle. I would like to find out how summary() estimates standard deviation of coefficient returned by mle(stats4), b...

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

In the trivial example inheritance hierarchy:

Copy object - keep polymorphism

The following code tries to copy an object and keep the original type.

Haskell polymorphic calls without complete type knowledge

I'm studying Haskell since a little while, so I'm a newbie.

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.

Accessing Derived Singleton Instance Throws Compiler Error

I am trying to implement a Singleton base class in my Unity3d project. But attempting to access the instance of a Singleton raises compiler errors:

java polymorphism

Consider the following code:

Java Polymorphic processing: Incorrect output?

In the following class I am trying to print details of Employees in a payroll system.

Is it really polymorphism?

Consider an interface called Shape which has a draw() method. Two classes Triangle and Circle implements the Shape interface and override the draw() method.

Django polymorphism in view

I have the following model, using Django Polymorphic:

Designing my program to avoid having to cast from base to derived class

Ok, I seem to be requiring forward casting from base to derived and I think it might be a design problem so I will explain what I’m doing and you can tell me what I need change.

Passing Child Builders

I have a case where I have something like:

Different Behavior Depending on the Data

Let's make it a simple example. Suppose I have a collection of Number objects, which can then be even or odd.

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. ...

boost::shared_ptr<> “explicit shared_ptr( Y * p ): px( p ), pn() // Y must be complete”

Can someone help me with the following error I get when trying to return an object polymorphically within a boost::smart_ptr:

Serialize QVector of polymorphic pointers

I have an AbstractIndex defining the interface for its Items and the sorting and query algorithms. Further I have several concrete indizes like in the example below a FileIndex. Now I want to seria...

Is is good practice to add a dummy method into a superclass so the subclass can override it?

I have a problem. It stems from calling a subclass method from a superclass, but with a twist. Any insight would be greatly appreciated.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.