inheritance

How can I avoid dynamic_cast in my C++ code?

Let's say I have the following class structure: class Car; class FooCar : public Car; class BarCar : public Car; class Engine; class FooEngine : public Engine; class BarEngine : public Engine; Let's also give a Car a handle to its Engine. A FooCar will be created with a FooEngine* and a BarCar will be created with a BarEngine*. Is ...

How can a descendant UserControl intercept events fired by its base class?

I have a base UserControl (BaseControl.cs) which has an OK and Cancel buttons on it. When the buttons are clicked, an event is fired. Typically other UserControl objects inherit from the BaseControl. Finally the descendant UserControl objects are placed on a WinForm, where they hook into the events for clicking Ok/Cancel buttons. My...

What's the best way to add custom functionality to existing code in C#?

Say, for example, I have many web applications using the same class library compiled into a dll in C# and I want to update a specific method of a class for a particular application. I don't want to change the existing code because it will affect everyone, and I don't want to inherit from a class to create a new one. I just want to change...

When to use inheritance?

Me and my friend had a little debate. I had to implement a "browser process watcher" class which invokes an event whenever the browser that is being watched (let's say Internet explorer) is running. We created a "Process watcher" class, and here starts the debate: He said that the constructor should only accept strings (like "iexplore....

How to obtain a property value on descendant class

I have a class (Descendant1) that inherits from a base class (BaseClass). An instance of a descendant class is passed into a method that takes BaseClass as a parameter. Then using reflection, it calls a property on the object. public class BaseClass { } public class Descendant1 : BaseClass { public string Test1 { get { return "te...

Why is using an abstract class for DataBinding in WPF different from using an Interface?

As we all know, we can't use DataTemplates with Interfaces, but apparently (old question) we can use abstract classes. Why? The multiple inheritance argument goes for abstract classes as well... ...

"Inherit not, contain" or "inherit, not contain"

I have an application which spawns a lot of child objects and each of them works with some global application objects e.g. registers itself in the global application registry, updates application statistics etc. How should application transfer the ability to access those global objects to the children? Should every child inherit from st...

WCF and Interface Inheritance - Is this a terrible thing to do?

My application has 2 "services", let's say one is a basic (integer) calculator, and one is a floating point calculator. I express these as interfaces like so: public interface IBasicCalculator { int Add( int a, int b ); } public interface IFloatingPointCalculator { double Add( double a, double b ); } I want to expose these via WCF....

Overloads of inherited member functions

Can a class overload methods that also exist in the publicly inherited interface? It seems like this is unambiguous and useful, but compilers (VC, Intel, GCC) all complain, at least by my construction. Below is a toy example. The inherited rebound() function has two clear overloads, yet this will not compile. If you rename the rebound()...

Using nested Master Pages

Hi. I'm very new to ASP.NET, help me please understand MasterPages conception more. I have Site.master with common header data (css, meta, etc), center form (blank) and footer (copyright info, contact us link, etc). <%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="_SiteMaster" %> <!DOCTYPE HTML PUBLIC...

Raising event from base class

I understand that one can raise an event in the class that the implementation declaration occurs, but I wish to raise the event at the base class level and have the derived class's event be raised: public interface IFoo { event EventHandler<FooEventArgs> FooValueChanged; void RaiseFooValueChanged(IFooView sender, FooEventArgs ...

cannot call base class protected functions?

I cant call protected function in my base class. Why? It looks something like this: class B : B2 { public: virtual f1(B*)=0; protected: virtual f2(B*) { codehere(); } } class D : public B { public: virtual f1(B*b) { return f2(b); } protected: virtual f2(B*b) { return b->f2(this); } } In msvc I get the error error C2248: 'name:...

Inherits from TextBox in WPF

Hello, I am trying to create a new WPF control called NumericTextBox. It inherits directly from TextBox. I added a new DependecyProperty called NumericValue that it could be used to bind a numeric property. Now, I would like to override the behavior of the TextProperty so that it could be accessed only as ReadOnly. Is it possible ...

css inheritance

I've just added the Twitter script to my website, and cannot, despite inexpertly consulting firebug, determine how to alter the css to make the feed appear uniform with the other text on my page. The page in question is http://willworth.co.uk/latest.htm Any help would be greatly appreciated Thank you in advance. As I improve, I wi...

asp.net: partial classes and inheritance

I have a class split across two files. One of these is generated, the other contains the non-generated stuff. I want my class to inherit from a base class. Do I need to have both files inherit? Or will the class inherit from the base class if either partial class In generated foo.vb: Partial Public Class Foo Inherits BaseCl...

Return Inherited Generics as Base Generic

I have BaseAbstractClass(of T as WebControl) (VB Generics) which inherits WebControl. BaseAbstractClass is inherited by ConcreteWrapper1, ConcreteWrapper2, and lastly, to shake things up a bit, ConcreteWrapper4. Each of these would inherit BaseAbstractClass using a different class inherited from WebControl. What I would like to do is...

Make a copy of an unknown concrete type in c++

Suppose we have the following class hierarchy: class Base { ... }; class Derived1 : public Base { ... }; class Derived2 : public Base { ... }; Given a Base* which could point to either a Derived1 or Derived2 object how can I make a copy of the actual object given that it's concrete type is unknown. I thought of defining ...

C# - Constructors and Inheritance

I have two classes declared like this: class Object1 { protected ulong guid; protected uint type; public Object1(ulong Guid, uint Type) { this.guid = Guid; this.type = Type } // other details omitted } class Object2 : Object1 { // details omitted } In the client code, I want to be able to ...

Inheritance in Java - creating an object of the subclass invokes also the constructor of the superclass. Why exactly?

Hallo, I have a question about inheritance in Java. I have two classes A and B, and class B, inherits from A: public class A { public A() { System.out.println("Hi!"); } } public class B extends A { public B() { System.out.println("Bye!"); } public static void main(String[] args) { ...

Validating Python Arguments in Subclasses

I'm trying to validate a few python arguments. Until we get the new static typing in Python 3.0, what is the best way of going about this. Here is an example of what I am attempting: class A(object): @accepts(int, int, int) def __init__(a, b, c): pass class B(A): @accepts(int, int, int, int) def __init__(a, b, ...