inheritance

Using inheritance and polymorphism to solve a common game problem

I have two classes; let's call them Ogre and Wizard. (All fields are public to make the example easier to type in.) public class Ogre { int weight; int height; int axeLength; } public class Wizard { int age; int IQ; int height; } In each class I can create a method called, say, battle() that will determine who will win if...

Objects of the same name in base and derived class not getting flagged as an error

class Base { public: type1 m_Pants; }; class Derived : Base { public: type2 m_Pants }; This essentially didn't get flagged as an error, but was creating all kinds of clobbering and issues throughout a project. Does anyone know of a technicality that wouldn't flag this? ...

How to copy generically superclass instances to subclass instances?

Hi @all, I have a class hierarchy / inheritance like this: public class A { private String name; // with getters & setters public void doAWithName(){ ... } } public class B extends A { public void doBWithName(){ // a differnt implementation to what I do in class A } } public class C extends ...

C++ abstract class template + type-specific subclass = trouble with linker

Hi there, The project in question is about different endpoints communicating with each other. An endpoint sends events (beyond the scope of the current problem) and can process incoming events. Each event is represented in a generic object as follows: #pragma interface ... // some includes template<typename T> class Event { public:...

Force the use of interface instead of concrete implementation in declaration (.NET)

In C++, you can do the following: class base_class { public: virtual void do_something() = 0; }; class derived_class : public base_class { private: virtual void do_something() { std::cout << "do_something() called"; } }; The derived_class overrides the method do_something() and makes it private. The effect is...

symfony + doctrine + inheritance, how to make them work?

I am beginning to work with Symfony, I've found some documentation about inheritance. But also found this discouraging article, which make me doubt if Doctrine handles inheritance any good at all... Has anyone find a smart solution for inheritance in Symfony+Doctrine? As an example, I have already structured the database something lik...

Constructors with inheritance in c++

If you have 3 classes, with arrows going from parent to child classes (i.e. "A -> B" means "B inherits from A": shape -> 2d shape -> circle +----> 3d shape -> sphere When you write your constructor for the circle class, would you ever just initialize the grandparent Shape object and then your current object, skipping the middle cla...

(Not So) Silly Objective-C inheritance problem when using property - GCC Bug?

Update - Many people are insisting I need to declare an iVar for the property. Some are saying not so, as I am using Modern Runtime (64 bit). I can confirm that I have been successfully using @property without iVars for months now. Therefore, I think the 'correct' answer is an explanation as to why on 64bit I suddenly have to explicit...

C#: is there way for a class to 'remove' methods that it has inherited

Is there way for a class to 'remove' methods that it has inherited? eg. If I don't want my class to have a ToString() method can I do something so that it is no longer available? ...

How can I create a list of classes in C# to iterate over in a loop

Suppose I have class animal and classes cat and dog extending it. I want to do something along the lines of: foreach (class a in {cat, dog}) if (a.isValid(parameters)) doStuff(); isValid is a static method from animal that just checks if the given parameters define an object of the given type doStuff means I'm doing stuf...

Using LINQ to SQL with multiple databases

I am working on a new project and hoping to use LINQ to SQL for the data access but have come across the following issue. I need to have my application access 3 databases with similar but not the same table structure, for example Database1 and Database 2 has a table called tblCustomer with 2 columns CustomerKey and CustomerName Databa...

Is it possible to override a property and return a derived type in VB.NET?

Consider the following classes representing an Ordering system: Public Class OrderBase Public MustOverride Property OrderItem as OrderItemBase End Class Public Class OrderItemBase End Class Now, suppose we want to extend these classes to a more specific set of order classes, keeping the aggregate nature of OrderBase: Public Clas...

Singleton with inheritance, Derived class is not able to get instantiated in parent?

Below code instantiates a derived singleton object based on environment variable. The compiler errors saying error C2512: 'Dotted' : no appropriate default constructor. I don't understand what the compiler is complaining about. EDIT: Fixed issues with implementing the get instance method which requires definition of both the parent and ...

Getting "value is not defined" while inheriting a type

I can't see what I am doing wrong, as the files are in the correct order. In this case it is: BaseDAO.fs CreateDatabase.fs They are in the same namespace, but even when I had them in different modules, and opened the module in CreateDatabase the same error. The error is: Error 1 The value or constructor 'execNonQuery' is not d...

Custom Image Button and Radio/Toggle Button from Common Base Class

Hi All, I would like to create a set of custom controls that are basically image buttons (it's a little more complex than that, but that's the underlying effect I'm going for) that I've seen a few different examples for. However, I would like to further extend that to also allow radio/toggle buttons. What I'd like to do is have a comm...

How to find the first declaring method for a reference method

Suppose you have a generic interface and an implementation: public interface MyInterface<T> { void foo(T param); } public class MyImplementation<T> implements MyInterface<T> { void foo(T param) { } } These two types are framework types I provide. In the next step I want allow users to extend that interface as well as redecla...

Javascript Getting Objects to Fallback to One Another

Here's a ugly bit of Javascript it would be nice to find a workaround. Javascript has no classes, and that is a good thing. But it implements fallback between objects in a rather ugly way. The foundational construct should be to have one object that, when a property fails to be found, it falls back to another object. So if we want a to...

What's the behavior when you re-specify an interface already implemented by a base class

Given the following code: public interface IExample { ... } public abstract class BaseExample: IExample { ... } public class ExampleA : BaseExample { ... } public class ExampleB : BaseExample, IExample { ... } Are there any benefits or drawbacks in writing code like ExampleB? My guess is that re-specifying IExample in the derived cl...

OOP design issue: Polymorphism

I'm trying to solve a design issue using inheritance based polymorphism and dynamic binding. I have an abstract superclass and two subclasses. The superclass contains common behaviour. SubClassA and SubClassB define some different methods: SubClassA defines a method performTransform(), but SubClassB does not. So the following example 1...

Override An Existing Property as a Child form of its return type

I apologize if that title is confusing. This question may be a result of lack of coffee and/or sleep, but my mind is not working correctly right now. Anyways, I have an inheritance tree like so (I know the architecture isn't ideal): BaseClass GeneralForm : Inherits BaseClass SpecificForm : Inherits GeneralForm And an object like so...