inheritance

Using member-hiding (`new`) to get more specific return type

I'm considering to use new to redefine members in subclasses to make more specific return type available. The question is: is this a good idea, or is it asking for troubles? The problem to be solves is when there are several "mirrored" class hierarchies, where types from every hierarical layer are referencing to the same level of anothe...

Design a database with or without inheritance

Hello, I am trying to understand inheritance and how to use it with PostgreSQL. For this reason i design a database in the excel file. In the 1st columns you can see the table w/o inheritance while in the 2nd part of the sheet you can see the tables with INHERITANCE. Can you give me your opinion and help on the following? 1. Which is th...

C# : dynamic polymorphism with non polymorphic classes

Hello, I have a set of classes which I didn't write, and they're read only. Let's say, for the example, that those classes are the following ones: public class Base { } public class B : Base { } public class C : B { } public class D : Base { } I want to add a method Foo() on all these classes, I am using extension methods: public st...

How to map Sets when using NHibernate Join Table per Subclass

I have the following HBMs (the sample is purely fictional, so don't try to understand the business needs) Class Document <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> <class name="Document" discriminator-value="Document"> <id name="Id" type="long"> <generator class="native" /> </id> <discriminator /> <p...

How to Add New Members to Struct

These are functions and Struct declarations I have, and I'm not allowed to change them. DerivedA giveDerivedA (); DerivedB giveDerivedB (); struct Base{ QString elementId; QString elementType; }; struct DerivedA : Base { int a; int b; }; struct DerivedB : Base { int c; int d; }; But what I need is something ...

Inheritance strategy in Hibernate: making an entity abstract and replacing with sub classes

I have currently existing database and hibernate mapping for it. There is a central table and corresponding entity (PersistentObject). Many of the other tables and entities refer to PersistentObject via @ManyToOne or @OneToOne mapping. Now I'd like to make current PersistentObject abstract and introduce two sub classes Sub1Object and Su...

FxCop TypeNode.IsDerivedFrom method works unexpectedly for types from different assemblies.

Hello I have base type "Base" in assembly "A" and derived type "Child" in assembly "B". I'm using FxCop to find in assembly "B" types derived from "Base" like this: var baseAssemblyNode = AssemblyNode.GetAssembly("A.dll"), true, true, false); var baseType = baseAssemblyNode.Types.Single(t => t.Name.Name == "Base"); var assemblyNode =...

asp.net extending IPrincipal

I would like to extend IPrincipal in asp.net to allow me to get the usertype that I will define. I would like to make it possible to do this in a controller string type = User.UserType then in my extension method i will have a method like public string UserType() { // do some database access return userType } how can I do th...

operator= in subclass

Hi, I'm quite confused about how to solve the following problem (search both on SO and google didn't help much). Say we have a class defining basic operators and a simple vector as only data and add only additional methods in inherited classes: class Foo { public: // this only copies the data Foo& operator=(const F...

Function overloading and inheritance

Possible Duplicate: Why does an overridden function in the derived class hide other overloads of the base class? I recently came across this interesting inheritance example - class FirstClass { public: void MethodA (int) { cout << "ONE\n";} void MethodA (int, int) { cout << "TWO\n";} }; class SecondClass : pu...

How does the Rails' single table inheritance works?

I have a user table, and a teacher that I newly created. The teacher is sub class of user, so, I use scaffold generator to generate the teacher table, than, I modify the model to do teacher is subclass of user. After all that, I did a db:migrate. Then, I go to http://localhost:3000/teachers/new It shows an error: undefined method `te...

How do you control the types of objects you can add to an XElement?

Is there a way to create a class that derives from XElement, but also control the types of objects that can be added to it? For example, say I have this... public class HtmlHead : XElement {} But I can't override the Add() method because it's down at the XContainer level. And even if I was to create a class that derives from XContain...

What happens if two ObjC categories override the same method?

I know of a couple of rules regarding Objective-C categories: Category methods should not override existing methods (class or instance) Two different categories implementing the same method for the same class will result in undefined behavior I would like to know what happens when I override one of my own category methods i...

Creating a namedtuple with a custom hash function

Say I have a namedtuple like this: fooTuple = namedtuple("fooTuple", "item1, item2") And I want the following function to be used for hashing: fooHash(self): return hash(self.item1) * (self.item2) I want this because I want the order of item1 and item2 to be irrelevant (I will do the same for the comparison-operator). I thought...

abstract class does not implement interface

I have an interface so class writers are forced to implement certain methods. I also want to allow some default implemented methods so i create a abstract class. The problem all classes inherit from the base class so i have some helper functions in there. I tried to write :IClass in with the abstract base but i got an error that the bas...

C++: Force the order of functions in the virtual method table?

Hello, How can i control the order of virtual functions in the virtual table? Are they laid out in the same order that they are declared in? When inheriting a class with a virtual table, is the virtual table of the inherited class an extension of the base class, or is an entirely new virtual table created with only the inherited classe...

Why do classes that implement an interface not count as the same type as the interface in Java?

I have out.load(output, transactions, columnHeaders, dataFormat); Where load is defined as: public boolean load(String outputfile, List<Transaction> transactions, List<String> columnHeaders, String dataFormat); and String output = ""; String dataFormat = ""; ArrayList<ARTransaction> transactions = new ArrayList<ARTransaction>(); ...

Deriving 2 times on Entity Framework

Hello everybody Let's say we have tables named A, B, C . C derived from B and B derived from A. So if i want to get C table, OfType(C) will bring result as expected. But if i wrote OfType(B) result will include entries of table C. How i could get result just for B ? Is there better solution of Entity Framework ? ...

inherit WPF window, why i can not see the Parent's buttons in the child's window

hi, i have a base WPF window and a second WPF window which derived from it. if i add new items to the child's window, i can not see the buttons that derived from the base window anymore. anyone? idea??? thanx! tali ...

C++ inheritance/template question

I have two classes, point and pixel: class point { public: point(int x, int y) : x(x), y(y) { }; private: int x, y; } template <class T> class pixel : public point { public: pixel(int x, int y, T val) : point(x, y), val(val) { }; private: T val; } Now here's my problem. I want to make ...