polymorphism

Adding class functionality via composition

Hello, Suppose we have an abstract class Element from which classes Triangle and Quadrilateral are derived from. Suppose yet that these classes are used in conjunction with interpolation methods that depend on the shape of the element. So, basically we create an abstract class InterpolationElement from which we derive InterpolationTri...

WCF with shared objects and derived classes on client

I have a WCF serivic and Im sharing types with a client in a shared assembly. If the client create a derived class will it be possible to pass back the derived type to the service so that I can read the added properties through reflection ? I tried but having issues with KnownTypes since the service dont know how to deserialize the deri...

Reverse Polymorphic Associations

I have a parent object, Post, which has the following children. has_one :link has_one :picture has_one :code These children are mutually exclusive. Is there a way to use polymorphic associations in reverse so that I don't have to have link_id, picture_id, and code_id fields in my Post table? ...

Polymorphism and checking if an object has a certain member method.

I'm developing a GUI library with a friend and we faced the problem of how to determine whether a certain element should be clickable or not (Or movable, or etc.). We decided to just check if a function exists for a specific object, all gui elements are stored in a vector with pointers to the base class. So for example if I have class...

Polymorphic QSharedPointer

I'm trying to use QSharedPointer in my polymorphic stucture, but I couldn't find right syntax to convert pointer of base class to pointer of derived class. struct Switch : State { int a; }; QSharedPointer <State> myState=QSharedPointer <State>(new Switch); QSharedPointer <Switch> mySwitchTest= ??? myState; What should I put in th...

are polymorphic join tables possible in Grails

Does anybody know if it is possible create and write to polymorphic join tables using grails. Are there any drawbacks from doing this ...

Catch derived exception when returning reference of base class type?

Hi, I'm writing a windows application in C++ and encountered the following problem when working with exceptions. I have a base exception class from which all other exceptions derive from. In the base class I have a method for the error message of any exception. That method then returns the exception (through '*this'). Now, the problem...

C++ : Multiple inheritance with polymorphism

Hi, (pardon the noob question in advance) I have 4 classes: class Person {}; class Student : public Person {}; class Employee : public Person {}; class StudentEmployee : public Student, public Employee {}; Essentially Person is the base class, which are directly subclassed by both Student and Employee. StudentEmployee employs multip...

How essential is polymorphism for writing a text editor?

Many years ago when I didn't know much about object oriented design I heard one guy said something like "How can you write a text editor without polymorphism?" I didn't know much about OOP and so I couldn't judge how wise that though was or ask any specific questions at that time. Now, after many years of software development (mostly C+...

JPA/toplink heterogeneous list of entities

Colleagues, Using JPA I need resolve following issue: at database level exits 3 entities (saying SuperEntity, DetailsAEntity and DetailsBEntity). SuperEntity contains common part of fields for DetailsAEntity and DetailsBEntity. So the question: is it possible to resolve collection of mixed elements DetailsAEntity and DetailsBEntity from...

Is there ever a reason to hide inherited members in an interface?

I understand that a class which inherits from another class may hide a property by using the new keyword. This, however, is hiding a specific implementation of the property, so I can see how it could be used. Is there any practical reason to hide members in interfaces which implement other interfaces? For example consider the example be...

Is the Visitor pattern the best way to refactor domain enums to classes?

If we want to refactor an enum (contained in the domain layer) to a polymorphic class, using "simple" abstract methods could be a bad idea, if all the switch and if statements we want to refactor are inside the other layers (like the business or the presentation layer), because we could end up to reference these layers inside the domain ...

Default implementation or abstract method?

Is it better to put a default implementation of a method in a superclass, and override it when subclasses want to deviate from this, or should you just leave the superclass method abstract, and have the normal implementation repeated across many subclasses? For example, a project I am involved in has a class that is used to specify the ...

What are the alternatives to subtype polymorphism in scala?

I'm interested to know the complete set of alternatives to subtype polymorphism in scala. ...

What is better - polymorphism or inheritance as a concept for operating with a .net library?

If I create a library with most functions meant for overwriting, meaning that you will need to put your logic into some of initial library functions to get what you want from library. will it be normal\usual\OK? will such library be called a framework? Example In my library I have CreateData function, lots of other functions and one, le...

Getting my conceptions about pointers and references straight (C++)

Hi guys I've been programming a while now at school, and I'm working on my first independent large project. I've been discovering a lot of things about programming that I haven't known before and it's been great. However, more and more, I feel like I no longer understand C++ as a language the more I delve into it. I'd like to get some ...

How to order by an attribute of a parent for a polymorphic model in ActiveRecord?

I think I worded that correctly... I have a model called asset which is polymorphic: class Asset < ActiveRecord::Base belongs_to :assetable, :polymorphic => true ... end I have a class level method that acts as a scope: def self.some_scope assets = Asset.joins(:assetable).where('assetable.approved_at IS NOT NULL').order('asse...

Inheritance in Lift Mapper or Record Framework

Is there a way to define proper a inheritance model in Lift using Mapper o Record Framework where there is a table for the parent class and one table for each son? ...

Passing different content that implements the same interface

I have multiple Linq2Sql Classes such as "Article" "NewsItem" "Product". They all have a title, they all have a unique ID and they all have a Summary. So, I created an interface called IContent public interface IContent { int Id { get; set; } String Title { get; set; } String Summary { get; set; } String HyperLink { ge...

Polymorphism with AutoMapper

I have these business classes: class BaseNode { public string name; } class CompositeNode : BaseNode { public List<BaseNode> childs = new List<BaseNode>(); } And this flat dto: class NodeDto { public string name; public List<NodeDto> childs; } (note how all der...