inheritance

How can one inspect a vtable in Visual C++?

Suppose one had inherited a complex codebase (in Visual C++, assume 2003 or perhaps later) with a large and complex inheritance graph. Suppose it's deep, and there's lots of virtual functions and possibly even multiple inheritance as well. (Yes, a bit of a maintenance nightmare). Any attempt to refactor this class hierarchy into somethin...

Selecting the Correct View for an Object Type

I've had this problem many times before, and I've never had a solution I felt good about. Let's say I have a Transaction base class and two derived classes AdjustmentTransaction and IssueTransaction. I have a list of transactions in the UI, and each transaction is of the concrete type AdjustmentTransaction or IssueTransaction. When I...

Overriding System.Web.Mvc.ViewMasterPage, where to make call to grab from cache?

Hi, I need to grab a value from the HttpCOntext.Items request cache, where should I do this? Is there a particular event or contsructor I should override? ...

Interface inheritance: what do you think of this:

Hi When reviewing our codebase, I found an inheritance structure that resembles the following pattern: interface IBase { void Method1(); void Method2(); } interface IInterface2 : IBase { void Method3(); } class Class1 : IInterface2 { ... } class Class2 : IInterface2 { ... } class Class3 : IInterface2 { ... ...

How to Create Establish Inheritance Between Objects in JavaScript?

I have the following code that creates two objects (ProfileManager and EmployerManager) where the object EmployerManager is supposed to inherit from the object ProfileManager. However, when I do alert(pm instanceof ProfileManager); it returns false. function ProfileFactory(profileType) { switch(profileType) { case 'employe...

inheritance from two parent classes

Hi, I read about this ages ago but never tried it now I can't remember if this is possible or not. Is it possible to extend a class from two parents on php5 e.g. class_d extends class_c and class_b moreover can you do this if class_c and class_b are themselves extended from class_a ... so you get something like this ...

Deriving an abstract class from concrete class

Let's say we have a concrete class Apple. (Apple objects can be instantiated.) Now, someone comes and derives an abstract class Peach from Apple. It's abstract because it introduces a new pure virtual function. The user of Peach is now forced to derive from it and define this new function. Is this a common pattern? Is this correct to do?...

C++ templates and inheritance

My C++ framework has Buttons. A Button derives from Control. So a function accepting a Control can take a Button as its argument. So far so good. I also have List<T>. However, List<Button> doesn't derive from List<Control>, which means a function accepting a list of Controls can't take a list of Buttons as its argument. This is unfortun...

How do you declare an interface in C++?

How do I setup a class that represents an interface? Is this just an abstract base class? ...

Registering derived classes with reflection, good or evil?

As we all know, when we derive a class and use polymorphism, someone, somewhere needs to know what class to instanciate. We can use factories, a big switch statement, if-else-if, etc. I just learnt from Bill K this is called Dependency Injection. My Question: Is it good practice to use reflection and attributes as the dependency injecti...

Extending enum

public enum myEnum { VAL1(10), VAL2(20), VAL3("hai") { public Object getValue() { return this.strVal; } public String showMsg() { return "This is your msg!"; } }; String strVal; Integer intVal; public Object getValue() { return this.intVal; } private myEnum(int i) { th...

Java dynamic binding and method overriding

Yesterday I had a two-hour technical phone interview (which I passed, woohoo!), but I completely muffed up the following question regarding dynamic binding in Java. And it's doubly puzzling because I use to teach this concept to undergraduates when I was a TA a few years ago, so the prospect that I gave them misinformation is a little d...

QAbstractTableModel inheritance vtable problem

Here's another problem with qt: I extend a QAbstractTableModel, but I get a compiling error ( I'm using cmake) // file.h #ifndef TABLEMODEL_H #define TABLEMODEL_H #include <QAbstractTableModel> class TableModel : public QAbstractTableModel { Q_OBJECT public: TableModel(QObject *parent = 0); int rowCount(const QModelIndex &parent = QM...

how do i inherit/overwrite a forced style from a windows theme?

currently i am forcing my WPF app to use the luna theme no matter what, with this XAML code <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Styles.xaml" /> <ResourceDictionary Source="NavigationCommands.xaml" /> <ResourceDict...

Conception of inheritance in object-oriented languages

I was discussing multiple inheritance vs. single inheritance with a friend of mine, and discovered that plainly, my conception of Object-Oriented design is completely different than his. I am mostly an Obj-C programmer, so Multiple Inheritance is not something I use daily. He is mostly a C++ programmer under Windows/PSP, so we probably ...

Shall I use "virtual" keyword for destructor of base-class which is actually an interface?

I have an abstract base class and derived class: type TInterfaceMethod = class public destructor Destroy; virtual; abstract; procedure Calculate; virtual; abstract; procedure PrepareForWork; virtual; abstract; end; type ConcreteMethod = class(TInterfaceMethod) private matrix: TMinMatrix; public constructor Crea...

Inheritance, Parent-Child and Overriding...

Just came across this quote in a book on OOP that I'm reading, A child is only allowed to augment functionality and add functionality. A child is never allowed to remove functionality. If you do find that a child need to remove functionality, this is an indication that the child should appear before the parent in the ...

Can I hold any data members in abstract base class?

I have an abstract class: type TInterfaceMethod = class abstract public destructor Destroy; virtual; abstract; function GetBasePlan: Word; virtual; abstract; procedure CountBasePlan; virtual; abstract; procedure Calculate; virtual; abstract; procedure PrepareForWork; virtual; abstract; end; ...

C++ design question - Network packets and serialization

I have, for my game, a Packet class, which represents network packet and consists basically of an array of data, and some pure virtual functions I would then like to have classes deriving from Packet, for example: StatePacket, PauseRequestPacket, etc. Each one of these sub-classes would implement the virtual functions, Handle(), which w...

Java Protected Access Not Working

In java, there's three levels of access: Public - Open to the world Private - Open only to the class Protected - Open only to the class and its subclasses (inheritance). So why does the java compiler allow this to happen? TestBlah.java: public class TestBlah { public static void main(String[] args) { Blah a = new Blah...