inheritance

C# memberwisecopy and descendants

I think there's good no answer but before I throw in the towel on doing this gracefully I'll ask here: I have a parent class which holds a bunch of data. These are used only to instantiate a descendant which takes the parent, modifies it and produces the final result. I see how to use MemberwiseCopy to make another instance of the par...

How do I implement 'Parameter Object' refactor in Python?

Right now I use the parameter object's class to be inherited like so class A(): def __init__(self,p1,p2): self.p1, self.p2 = p1, p2 class B(A): def __init__(self,b): self.p1, self.p2 = b.p1, b.p2 This trims up the absurdity of using the code but not the class code itself. So, I'd like to do the C++ thing and p...

Specializing a template by a template base class

I'm writing a template for which I'm trying to provide a specialization on a class which itself is a template class. When using it I'm actually instanciating it with derivitives of the templated class, so I have something like this: template<typename T> struct Arg { static inline const size_t Size(const T* arg) { return sizeof(T); }...

Overriding private methods in Java

As succinctly described here, overriding private methods in Java is invalid because a parent class's private methods are "automatically final, and hidden from the derived class". My question is largely academic. How is it not a violation of encapsulation to not allow a parent's private method to be "overridden" (ie, implemented indepen...

Extend from Generic Supertype?

In Java, am I able to extend from a generic supertype? According to this article, it looks like I should be able: http://www.ibm.com/developerworks/java/library/j-djc05133.html. However, when I do something similar in my application, I get the following error: "Cannot refer to the type parameter T as a supertype." Does anyone know if I...

Specify the supertype of a class upon instantiation/declaration?

Is it possible to specify the parent of a class when I instantiate/declare that class? For example, can I do something similar to this: MonitoredDevice<DeviceTypeToExtend> device = null; And then from that statement, the MonitoredDevice class would extend from the type parameter DeviceTypeToExtend. Now, I know that you can't use type ...

Objective C protocol as an equal to Java Interface?

Hi The question is not only regarding the headline, but more of a "how will I achieve this, without trying to force a Java/Flash design into an Objective C (iPhone)program". I have 6 views that extends UIView, these views all have different behavior but share certain methods, like -(void) update and -(void) changeState:(NSInteger)state...

c++ data alignment /member order & inheritance

hi! how do datamembers get aligned / ordered if inheritance / multiple inheritance is used? Is this compilerspecific? is there a way to specify in a derived class how the members (including the members from the baseclass) shall be ordered / aligned? Thanks! ...

Is it possible to project discriminator-value or class name in a polymorphic query?

Say I have abstract base class Animal then Dog and Cat classes. I'm mapping these via table-per-subclass (w/ discriminator). Is it possible to query Animals and also project the discriminator-value or class name? It seems I cannot project the discriminator column. I know when I list Animals, NHibernate creates the correct Animal type f...

Inherit from a generic base class, apply a constraint, and implement an interface in C#.

This is a syntax question. I have a generic class which is inheriting from a generic base class and is applying a constraint to one of the type parameters. I also want the derived class to implement an interface. For the life of me, I cannot seem to figure out the correct syntax. This is what I have: DerivedFoo<T1,T2> : ParentFoo<T1, T...

Where is "Inherits <baseclass>" in an Interop UserControl?

I'm looking at the Interop UserControl mechanism that's part of the "Interop Forms Toolkit" version 2.0. (This you to build a .Net UserControl that can be published as a COM object for use on VB6 forms.) I've started a new project using the "VB6 Interop UserControl" template, and what I see is a class definition that looks like this: ...

How do I get all instances that inherited from the same parent class in django

I have two models than inherited from the same abstract base class. I would expect to be able to get all instances from classes that are children of the base class with something like AbstractClass.objects.all() Of course I could join queries on all children but that's awful and it stops working if I add new children class. Is this p...

C++ class template of specific baseclass

Let's say I have the classes: class Base{}; class A: public Base{ int i; }; class B:public Base{ bool b; }; And now I want to define a templated class: template < typename T1, typename T2 > class BasePair{ T1 first; T2 second; }; But I want to define it such that only decendants of class Base can be used as templa...

Class inheritance problem in Java, constructors with and without params

Hi guys, I'm learning Java (2nd year IT student) and I'm having a little problem. With inheritance to be precise. Here's the code: class Bazowa { public Bazowa(int i) { System.out.println("konstruktor bazowy 1"); } public Bazowa(int j, int k) { System.out.println("konstruktor bazowy 2...

Efficiency of Hibernate's table-per-subclass inheritance strategy

I'm thinking about table layout for a Hibernate-managed class hierarchy, and certainly the table per subclass technique strikes me as the most appropriate in a general sense. However, thinking through the logic I have some concerns about its performance especially as the number of subclasses scale. To give a very brief (and classic) ex...

Design advice - When to use "virtual" and "sealed" effectively

Hi all, I'm writing a C# networking library (mostly as a learning exercise, it's not overly important to me if anyone actually ends up using it as I'm sure solutions are already out there). I'm fairly happy with my structure so far... I have a few layers of client/server available, that can communicate in raw bytes over sockets, or sli...

Overloading based on specialization in C++

I'm trying to create a function which is overloaded based on the specialization of its parameter, such as this: class DrawableObject...; class Mobile : public DrawableObject...; class Game { AddObject(DrawableObject * object) { // do something with object } AddObject(Mobile * object) { AddObject(dyna...

How can I find all the packages that inherit from a package in Perl?

I have a number of different sites that I download data from and massage into other formats (using Perl) for use at work, that are all run from one Perl script kinda like so: #! /usr/bin/perl use strict; use My::Package1; use My::Package2; my $p1 = My::Package1->new; $p1->download; my $p2 = My::Package2->new; $p2->download; and so ...

Inherit docstrings in Python class inheritance

I'm trying to do some class inheritance in Python. I'd like each class and inherited class to have good docstrings. So I think for the inherited class, I'd like it to: inherit the base class docstring also append relevant extra documentation to the docstring Is there some "best practice" for doing this sort of docstring manipulation ...

Private inheritance from std::basic_string

Hi, I've been trying to learn more about private inheritance and decided to create a string_t class that inherits from std::basic_string. I know a lot of you will tell me inheriting from STL classes is a bad idea and that it's better to just create global functions that accept references to instances of these classes if I want to extend ...