inheritance

Inheritance of static members in PHP

In PHP, if a static attribute is defined in the parent class, it cannot be overridden in a child class. But I'm wondering if there's any way around this. I'm trying to write a wrapper for someone else's (somewhat clunky) function. The function in question can be applied to lots of different data types but requires different flags and o...

Should Tuples Subclass Each Other?

Given a set of tuple classes in an OOP language: Pair, Triple and Quad, should Triple subclass Pair, and Quad subclass Triple? The issue, as I see it, is whether a Triple should be substitutable as a Pair, and likewise Quad for Triple or Pair. Whether Triple is also a Pair and Quad is also a Triple and a Pair. In one context, such a r...

Named constructor and inheritance

I'm working on C++ framework and would like to apply automatic memory management to a number of core classes. So far, I have the standard approach which is class Foo { public: static shared_ptr<Foo> init() { return shared_ptr<Foo>(new Foo); } ~Foo() { } protected: Foo() { } }; // Example of use shared_...

How to determine an object's class (in Java) ?

If class B and class C extend class A and I have an object of type B or C, how can I determine which it instantiates? ...

Adding Plugin Support : Interface or Base class to inherit?

I'm adding plugin support to my .NET application. A base class sounds reasonable to me, so people can inherit it and override certain calls as well can keep the default functionality or can use some internal helper functions. Why would I choose interface instead of a base plugin class to inherit? Could you tell which design I should ch...

How do I code these generic functions and classes inheritances correctly? (VB .NET)

I have a function which I need to call for three different types, with the underlying logic remaining the same for all the different types, so I figured it would be best to write this function using generics. Here is the basic outline of the classes and functions involved: 'PO Base class' Public MustInherit Class ProductionOrder P...

Linq to SQL Inheritance Question

I guess I'm not quite sure how the Linq inheritance is supposed to work. I have a "User" entity and I want to have two additional entities called "Creator" and "Assigned" that inherit from the "User" entity (basically they should just have the same exact properties as the User entity) I don't need any additional properties. I can do th...

Polymorphism across C++ and Ruby using SWIG

I use SWIG to wrap a Ruby script around a C++ library. In Ruby, I can inherit from a C++ class, but I cannot pass the resulting pointer to a C++ function in a polymorphic way. Here is a concrete example. The SWIG interface file defines base class Animal with virtual function sound(): [animals.i] %module(directors="1") animals %{ #i...

Preventing Virtual Method Implementation in C++

I have the following class hierarchy in C++: class Base { virtual void apply() = 0; }; class Derived : public Base { virtual void apply() { // implementation here that uses derived_specialty } virtual void derived_specialty() = 0; }; class Implementation : public Derived { virtual void derived_specialt...

Method chaining + inheritance don't play well together?

Consider: // member data omitted for brevity // assume that "setAngle" needs to be implemented separately // in Label and Image, and that Button does need to inherit // Label, rather than, say, contain one (etc) struct Widget { Widget& move(Point newPos) { pos = newPos; return *this; } }; struct Label : Widget { Label& setTex...

Overriding ReadOnly Property in a subclass to make it Read/Write (VB.NET)

In C# I can have a base class with a property containing just a getter. Subclasses can then override the property and give it both a getter and a setter. This doesn't seem possible in VB.NET with properties since the property statement itself must describe whether it is ReadOnly or not. In my example below, it doesn't let me make the ...

Single Table Inheritance And where to use it in Rails

I am stuck in a weird Design problem, I am working on a two type of profiles Models, User profile (belongs to User) others that are maintain in-site as "bots" (doesn't belong to anybody) The typical OO behaviour of these two types of Profiles is same but only the important attributes/properties are common ( the very important on...

How to inherit a MFC dialog box?

Hi all, I have created a dialog box (cMyDialog). I am planning to duplicate cMyDialog and called it cMyDialog2. Can I know in MFC, how can I do inheritance? I want the cMyDialog2 to inherit all the IDDs from cMyDialog1 so that I do not have to copy and paste the codes from cMyDialog1 and cMyDialog2. The purpose of cMyDialog2 is to inhe...

Does every object of virtual class have a pointer to vtable?

Does every object of virtual class have a pointer to vtable? Or only the object of base class with virtual function has it? Where did the vtable stored? code section or data section of process? ...

Overriding function with enum/int

If there was a base class DeriveMe that had a function virtual void DoSomething(int) and a class that inherits DeriveMe called DerivedThat that had a function void DoSomething(SomeEnum)...would the DerivedThat override the base class DoSomething because enums evaluate to ints during compile time in C++? I could try this by making DoSome...

Generic method is picking up type of base class

I have the following classes (trimmed to only show the basic structure): public abstract class BaseModel { public bool PersistChanges() { // Context is of type "ObjectContext" DatabaseHelper.Context.SafelyPersistChanges(this); } } public static class ObjectContextExtensions { public static bool SafelyPersist...

Entity Framework - Table Per Type Inheritance - Existing Database

I want to implement Table Per Type inheritance with Entity framework for an existing database. The database: The inheritance for ImageParagraphs works perfect, but I am not able to make a Table Per Type inheritance with LinkListParagraph because of the different primary keys (ParagraphID; ParagraphID+LinkID): Error 1 Error 3003:...

public inheritance and tlb files

Say you have two assemblies (two dlls). The first contains a class called Base and the second contains a class called Derived which publicly inherits from Base. When I use the tlb files to create C++ classes in Visual Studio 2005, I get Base and Derived classes, but one is not a subclass of the other. There doesn't seem to be any IS-A ...

Possible memory leak?

Okay, so I have two classes, call them A and B--in that order in the code. Class B instantiates class A as an array, and class B also has an error message char* variable, which class A must set in the event of an error. I created a third class with a pure virtual function to set the errorMessage variable in B, then made B a child of that...

When are interfaces needed?

(In the context of .NET for what its worth) I tend to not use inheritance and rarely use interfaces. I came across someone who thinks interfaces are the best thing since spit. He uses them everywhere. I don't understand this and hence the questions that follow. I just want a check on my understanding of interfaces. If you are using...