polymorphism

Using Hibernate to persist a one-to-many list with a superclass type

Somebody asked this question on the Hibernate forums and I'm linking to it here because I have the same question. Nobody seemed to be of any help there so I'm hoping this might be more useful. Here it is: Question on Hibernate forum Thanks. ...

Search a collection for a sub type in C# / Linq

If I have a collection like List<SomeAbstractBaseType> someList = new List<SomeAbstractBaseType>(); And I have added two different child types to this collection (i.e. the two child types inherit from SomeAbstractBaseType) like this: someList.Add(someChildOfType1); someList.Add(someChildOfType2); someList.Add(someOtherChildOfType1);...

How to refactor an existing class to become polymorphic?

I have a class that is used as a member in many places in my project. Now, instead of this class I want to have a polymorphism, and the actual object will be created by some kind of factory. I have to choose between: Having to change all the places where I use the class - to call the factory and use a pointer instead of object directl...

If an overridden C++ function calls the parent function, which calls another virtual function, what is called?

I'm learning about polymorphism, and I am confused by this situation: Let's say I have the following C++ classes: class A{ ... virtual void Foo(){ Boo(); } virtual void Boo(){...} } class B : public A{ ... void Foo(){ A::Foo(); } void Boo(){...} } I create an instance of B and call it...

What kind of polymorphism is considered more idiomatic in C++?

C++ being a value oriented language doesn't seem to support OO (and thus sub-typing polymorphism) very well. As for parametric polymorphism, lack of type inference on type parameters and verbose syntax of templates makes them challenging to use. Please note that the only languages I know moderately well are Java (sub-typing polymorphism...

Polymorphic abstraction of Models and potential MI in rails?

We have Models like Supplier, Distributor, Vendor, Buyer in our schema. These entities have some common attributes ( like name, description, sales offices etc.) but mostly they have a divergent schema with different has_many :through associations ( a vendor has many stock_keeping_units , others do not) because of which they needed to be ...

Retrieving Polymorphic Hibernate Objects Using a Criteria Query

In my model I have an abstract "User" class, and multiple subclasses such as Applicant, HiringManager, and Interviewer. They are in a single table, and I have a single DAO to manage them all. User: @Entity @Table(name="User") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn( name="role", discriminatorTy...

Strongly-typed property reference to multiple classes with no common interface (C#)

The System.Windows.Documents namespace includes a number of classes with an Inlines property of type InlineCollection. For example, the Paragraph, Bold and Hyperlink classes all have this property. Each of these classes is decorated with ContentPropertyAttribute ... [ContentPropertyAttribute("Inlines")] public class Paragraph : Block ...

What should I do to make a Polymorphic Relationships in RoR?

I have a user table, and have a role column, that identify their role. Now, I want to add a "Student" table, that have the student's student number, and I also want to add a "Teacher", to store the teacher's salary. Both the Student and Teacher are the subclass of User. Now, I added a role column already in the User table, "T" = Teache...

Help with first Polymorphism class

I'm creating some random classes to understand Polymorphism better. Coding is as follows: Poly1: public abstract class Poly1 { int comPoly; } SubPoly1: public class SubPoly1 extends Poly1 { String testPoly; } SubPoly2: public class SubPoly2 extends Poly1 { int x; } testPoly: public class testPoly { public static v...

java IS-A relationship exam question confusion

From MasterExam: Which statements are true? (Choose all that apply) A. is-a relationship always rely on inheritance B. is-a relationship always rely on instance variables C. is-a relationship always require at least two class types D. is-a relationship always rely on polymorphism E. is-a relationship are always...

Is there ever a situation where derived class should hide …?

Perhaps a stupid question, but assuming base class A defines a virtual method V, is there ever a situation where it would make sense for a derived class C to hide A.V by declaring a new virtual method C.V with the same signature as A.V: class Program { static void Main(string[] args) { A a = new C(); a.Print...

Is it more efficient to access array elements through the array than to get them through a function?

I'm thinking about making an object that consists of a large grid, stored in a two dimensional array, and functions that work on that grid. If I want to iterate through the elements in this array outside of the object, the most readable and privacy-respectful way to access each grid element would be to use a function like grid.getElemen...

jump into interface implementation in Eclipse IDE

You know how in Eclipse, pressing F3 over a method will take you to its declaration? Well I have a method that is part of an interface; clicking F3 over this naturally takes me to the declaring interface. Obviously there is an object implementing this interface and this is where the method is actually implemented. I want, when I press ...

Is this a good implementation of Polymorphism?

This is working, but is this a good example of polymorphism? package mtm.test { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.MovieClip; public class TestDocument extends MovieClip { public function TestDocument() { var image:Image = new Image(); ...

Polymorphism in Clojure

Suppose I have a bunch of Clojure data structures, all of the same type - for example an object type defined by defrecord. What is the best way to get polymorphic behaviour across these structures? Would it be good practice to embed a function within the structure so that I can do something like: ((:my-method my-object) param1 param2)...

C++ inheritance question

I have a class like so: class A { public: virtual void foo() { bar() } protected: virtual void bar() { /* do stuff */ } } Now I want a derived class B that overrides both foo and bar. So I wrote the following: class B : public A { public: virtual void foo() { A::foo(); /* then other stuff */ } ...

Retrieving only the superclass in hibernate

I have a superclass and a subclass mapped to have a table for each class like this @Entity @Table(name="superclass_table") @Inheritance(strategy=InheritanceType.JOINED ) public class SuperClass { } @Entity @Table(name="subclass_table") public class SubClass extends SuperClass { } When I make session.createCriteria(SuperClass.cl...

Objective-C supertype polymorphism

Hi, I'm fairly new to Objective-C and wondering if it's possible to type objects as their supertype without receiving compiler warnings when assigning them, or if there is a recognised way of achieving the same thing? I realise that this is what type id is for but I have a base class with synthesized properties and if I try to use id ...

Interacting classes - organizing code

Hello to everyone! I have some problem with organizing classes properly. Suppose, I have some class ABase. When I want to create some different (more particular) abstraction of this class (denote it AParticular), I can use inheritance or just composition. Then it is easy to treat AParticular as ABase: in case of inheritance it is made a...