inheritance

Why does compiler complain when I try to convert to a base-class?

BaseClass.h class BaseClass { ... }; SubClass.h #include "BaseClass.h" class SubClass : public BaseClass { ... }; MyApp.h class BaseClass; class SubClass; class MyApp { SubClass *pObject; BaseClass *getObject() { return pObject; } }; I get a compiler error: error C2440: 'return' : cannot convert from 'SubClass *' to '...

How to have variables with dynamic data types in Java?

Hi, I need to have a UserProfile class that it's just that, a user profile. This user profile has some vital user data of course, but it also needs to have lists of messages sent from the user friends. I need to save these messages in LinkedList, ArrayList, HashMap and TreeMap. But only one at a time and not duplicate the message for e...

Is it possible to add JPA annotation to superclass instance variables?

Hi, I am creating entities that are the same for two different tables. In order do table mappings etc. different for the two entities but only have the rest of the code in one place - an abstract superclass. The best thing would be to be able to annotate generic stuff such as column names (since the will be identical) in the super clas...

Is there a mean to specify specialization-genralization (inheritance) of actors in UML?

I am just starting to use UML and have came to the following question: Some actors clearly are specialized versions of a natural entity. For example I've got Administrator and User actors which are clearly nothing but different roles of a user, Authorizer and Dispatcher which are services (and are going to be implemented this way). Shou...

how do I best create a set of list classes to match my business objects

I'm a bit fuzzy on the best way to solve the problem of needing a list for each of my business objects that implements some overridden functions. Here's the setup: I have a baseObject that sets up database, and has its proper Dispose() method All my other business objects inherit from it, and if necessary, override Dispose() Some of th...

inverse relation to multiple inheriting classes in django

Here are my schematic models: class Law(models.Model): ... class Bill(models.Model): ... # data for a proposed law, or change of an existing law class PrivateBill(Bill): ... # data for a Bill that was initiated by a parliament member class GovernmentBill(Bill): ... # data for a Bill that was initiated by the governme...

Could a derived-class object treated as if it's the same type of a bases class? <noobieQ/>

Say I got: class X_ { public: void do() { } } class Y_ : public X_ { } And I have this function: void foo(X_ whatever) { whatever.do(); } Can I send a "Y_" object to the foo function, would this work? I just realized that I could have tested this myself :) ...

Can I "inherit" a delegate? Looking for ways to combine Moq and MSpec without conflicts around It...

I have started to use MSpec for BDD, and since long ago I use Moq as my mocking framework. However, they both define It, which means I can't have using Moq and using Machine.Specifications in the same code file without having to specify the namespace explicitly each time I use It. Anyone who's used MSpec knows this isn't really an option...

How to deal with interchangable base classes in Java

I have an issue with some inheritance I'm doing. Basically, I have an abstract class called LineCalculator, which, as it suggests, calculates lines of an equation. From there, I inherit this base class in a LinearLineCalculator, which calculates lines on a Cartesian coordinate system, and a PolarLineCalculator, which calculated lines on ...

PHP: Extending static member arrays

I'm having the following scenario: class A { public static $arr=array(1,2); } class B extends A { public static $arr=array(3,4); } Is there any way to combine these 2 arrays so B::$arr is 1,2,3,4? I don't need to alter these arrays, but I can't declare them als const, as PHP doesn't allow const arrays.http://stackoverflow.com/questio...

Why is Rails before_filter called twice when the controller is subclassed?

I'm at Rails 2.3.5 and I have this problem: class BaseController < ApplicationController before_filter :foo, :only => [:index] end class ChildController < BaseController before_filter :foo, :only => [:index, :show, :other, :actions] end The problem is that on ChildController, the :foo before filter gets called twice. I've tried ...

How to access the backing field of a base class using fluent nhibernate?

How do i set the Access Strategy in the mapping class to point to the base _photos field? public class Content { private IList<Photo> _photos; public Content() { _photos = new List<Photo>(); } public virtual IEnumerable<Photo> Photos { get { return _photos; } } public virtual void AddPhoto() {...}...

Calling an Overridden Method from a Parent-Class Constructor

I tried calling an overridden method from a constructor of a parent class and noticed different behavior across languages. C++ - echoes A.foo() class A{ public: A(){foo();} virtual void foo(){cout<<"A.foo()";} }; class B : public A{ public: B(){} void foo(){cout<<"B.foo()";} }; int main(){ B *b = new B()...

Correct CSS inheritance behavior for properties that aren't inherited?

So say we you have a CSS property that is not inherited by default. We'll call it "foo" and its default value is "black". Then we make the following html. <div id="div1" style="foo: red;"> <div id="div2"> <div id="div3" style="foo: inherit;"> </div> </div> </div> Since this property does not inherit by default, you'd think tha...

C# casting question: from IEnumerable to custom type

I have a custom class called Rows that implements IEnumerable<Row>. I often use LINQ queries on Rows instances: Rows rows = new Rows { row1, row2, row3 }; IEnumerable<Row> particularRows = rows.Where<Row>(row => condition); What I would like is to be able to do the following: Rows rows = new Rows { row1, row2, row3 }; Rows particula...

When calling a static method on parent class, can the parent class deduce the type on the child (C#)?

Suppose we have 2 classes, Child, and the class from which it inherits, Parent. class Parent { public static void MyFunction(){} } class Child : Parent { } Is it possible to determine in the parent class how the method was called? Because we can call it two ways: Parent.MyFunction(); Child.MyFunction(); My current approach wa...

Hibernate subclass with foreign key relationships

I need some help defining the following object hierarchy/ database relationship in Hibernate From the object sense – Agent is inherited from Person and Agency is inherited from Organization. they are inherited from Party which can have multiple Addresses associated with it The database consists of Agent -ID -Name -PartyID (referenc...

Asp.net mvc inheritance controllers

Hi, I'm studing asp.net mvc and in my test project I have some problems with inheritance: In my model I use inheritanse in few entities: public class Employee:Entity { /* few public properties */ } It is the base class. And descendants: public class RecruitmentOfficeEmployee: Employee { public virtual Rec...

Fun with casting and inheritance

NOTE: This question is written in a C# like pseudo code, but I am really going to ask which languages have a solution. Please don't get hung up on syntax. Say I have two classes: class AngleLabel: CustomLabel { public bool Bold; // Just upping the visibility to public // code to allow the label to be on an angle } clas...

Implementation question involving implementing an interface

I'm writing a set of collection classes for different types of Trees. I'm doing this as a learning exercise and I'm also hoping it turns out to be something useful. I really want to do this the right way and so I've been reading Effective Java and I've also been looking at the way Joshua Bloch implemented the collection classes by lookin...