inheritance

What is going on here in PHP with classes?

If I have this code, the string "test" is echoed. This is in PHP 5.3. Is this some oversight that shouldn't be relied on, or is it some way of achieving multiple inheritence in PHP? class Test1 { function getName() { return $this->name; } } class Test2 { public $name = 'test'; function getName() { ...

How can I create factory? Client can set data for methods which are not in defined in interface?(Design Problem)

Hello, I am having little design problem: I have one factory which will create object of with one type or another type. But my client requirement is to give(feed) the data(via setter methods) from outside world to the concrete class of type-1 not for type-2. If I place these setter methods in interface, those need to be implemented for...

Getting current class in method call

class A: def x ( self ): print( self.__class__ ) class B ( A ): pass b = B() b.x() In the above situation, is there any way for the method x to get a reference to class A instead of B? Of course simply writing print( A ) is not allowed, as I want to add some functionality with a decorator that needs the class A (and a...

Inheritance of button

I designed a button How do I inherit the rest of this button? ...

Why does Ruby module inclusion exclude the module's singleton class?

When classes are inherited in Ruby the singleton classes are also inherited: class A def self.hello puts "hello" end end class B < A end B.hello #=> "hello" Yet with modules, this is not the case: module M def self.goodbye puts "goodbye" end end class A include M end A.goodbye #=> NameError To get around this ...

C++ reference in base class constructor

I have a logic in base class constructor. The result of the logic has to be captured in the derived class constructor in a temporary variable. Is there a way to do it? For example class Base { Base() { int temp_value = some_logic; } }; class Derived : public Base { Derived() { // need the temp value here.. } }; Thanks, Goku...

WPF - How to avoid TextBox override of Foreground of inherited TextElement.Foreground

Hey guys, TextBox.ForegroundProperty is inherited from TextElement.ForegroundProperty. Unfortunately TextBoxs DefaultStyle sets this Property again. That means that setting TextElement.Foreground on any parent container of the TextBox does not affect the TextBoxs Foreground Color. Do you know any elegant way to avoid this behavior? I ...

How do I use a generic base class two levels down in an inheritance tree?

Imagine that I have a generic base class like this: public abstract class AnimalDTO<TA, TB> { public static TB ToDTO(TA entity) { return ConvertToDTO<TB>(entity); } } The class is responsible for being able to convert a passed-in entity to a DTO. I have a class that uses this generic class: public class MammalDTO...

Entity Framework inheritance association problem

Hi everyone, I am trying to resolve a situation I ran into when implementing EF with my project. I have absolved the table-per-type approach, in my case the ActionUpdate derives from the ActionHistory and that works fine. What I am trying to achieve is to derive the ActionUpdate from the ActionHistory, and to have a navigation propert...

Does Maven support properties inheritance?

Let's say I have a property foo defined in my parent POM. Is it possible to access the "foo" propery in any of the children? To give you a bit of context, I am working on a multi-module maven project with inheritance. I did search the web and some forums for a while and could not find the answer. Many thanks in advance. ...

C# Class Inheritance

I am working with insurance and have two different policy types - motor and household, represented by two different classes, Motor and Household. Both have several bits of data in common, so both would inherit from another class called Policy. When a user logs into the app, they could have either a motor or a household policy, so the a...

Obscure compiler error on piece of beginner C++ code

Hello guys, g++ is letting out an obscure error, undefined reference to '__gxx_personality_sj0' in two lines of my project. What does this mean in this context? I googled a lot and found out this is usually related to the inclusion of C code in C++ or something like that, which is not what I'm going for. (I know the code isn't high qual...

single-table-per-hierarchy mapping error

I got the following mappings <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="false"> <subclass name="Module.CRM.Models.CallRecord, Module.CRM" extends="Gate.Calls.CallRecord, Gate.SDK" discriminator-value="call_record_id"> <property name="ContactId" column="contact_id" /> ...

nhibernate inheritance

I have two tables: call_records crm_call_records call_records do not know that crm_call_records and their corresponding classes exists in different assemblies. I can therefore not add a subclass mapping in the mapping file for call_records. crm_call_records has a column named call_record_id which contains the value of the PK in cal...

Design Pattern for Unique Object Per ID system

I have the follow classes (C# for example) class A { private static Dictionary<int, A> idLookup; .... private A(id) {...} public static A Get(id) { //does some magic if (...) { return idLookup[id]; } else { A a = new A(id); idLookup[a.id] = a; return a; } } } class B { private static...

Type class pattern in Scala doesn't consider inheritance?

I am designing an API using type classes in some cases however I have encountered a problem with implicit resolution. As shown below, if there is an implicit object for type A but an object of type B extends A is passed to the method, then an implicit object cannot be found. Is there a way to make this work or do callers have to put im...

Django inline for model inheritance target

Hi, I am trying to solve problem related to model inheritance in Django. I have four relevant models: Order, OrderItem which has ForeignKey to Order and then there is Orderable model which is model inheritance superclass to children models like Fee, RentedProduct etc. In python, it goes like this (posting only relevant parts): class Ord...

Django model inheritance problem. How to solve?

Hello all, I have an existing app with the following model class Contact(models.Model): lastname = models.CharField(max_length=200) firstname = models.CharField(max_length=200) ... class Journalist(Contact): pass I have a Contact in my database and I would like that it becomes a Journalist. In raw sql, it seems...

Accessing overridden base class member from derived class object

I have two classes: class A { public: int i; }; class B : public A { public: int i; }; Suppose that I created an object for class B B b; Is it possible to access A::i using b? ...

Generics - Type mismatch when providing a concrete type to a generic class

Hi, Simple Java generics question: I have two classes - one of which uses generics to define its type, the other which extends this class providing a concrete type. public class Box<Item> { ... } public class Toolbox extends Box<Tool>{ ... } Given that Toolbox extends Box providing a Tool as the actual type for the generic ...