overriding

Overriding the java equals() method quirk

I ran into an interesting (and very frustrating) issue with the equals() method today which caused what I thought to be a well tested class to crash and cause a bug that took me a very long time to track down. Just for completeness, I wasn't using an IDE or debugger - just good old fashioned text editor and System.out's. Time was very ...

How does reflection tell me when a property is hiding an inherited member with the 'new' keyword?

So if I have: public class ChildClass : BaseClass { public new virtual string TempProperty { get; set; } } public class BaseClass { public virtual string TempProperty { get; set; } } How can I use reflection to see that ChildClass is hiding the Base implementation of TempProperty? I'd like the answer to be agnostic between c...

Help With Overriding and Inheritance...

Ok, bear with me guys and girls as I'm learning. Here's my question. I can't figure out why I can't override a method from a parent class. Here's the code from the base class (yes, I pilfered the java code from an OOP book and am trying to rewrite it in C#). using System; public class MoodyObject { protected String getMood() ...

Poll: Correct behavior of equality when passed object does not match LHS type?

I asked a related question about findbugs, but let's ask a more general question. Suppose that I am working with an object-oriented language in which polymorphism is possible. Suppose that the language supports static type checking (e.g., Java, C++) Suppose that the language does not allow variance in parameters (e.g., Java, again...)...

Detecting Overridden Methods in Perl

Last week I was bitten twice by accidentally overriding methods in a subclass. While I am not a fan of inheritance, we (ab)use this in our application at work. What I would like to do is provide some declarative syntax for stating that a method is overriding a parent method. Something like this: use Attribute::Override; use parent '...

Can I call a base class's virtual function if I'm overriding it?

Say I have class Foo and Bar set up like this: class Foo { public: int x; virtual void printStuff() { std::cout << x << std::endl; } }; class Bar : public Foo { public: int y; void printStuff() { // I would like to call Foo.printStuff() here... std::cout << y << std::endl; } }; ...

Does the super class not call the overridden method?

I have the following classes: class foo { public void a() { print("a"); } public void b() { a(); } } class bar extends foo { public void a() { print("overwritten a"); } } When I now call bar.b() I want it call the overwritten method a() in foo. It does, however, print "a". ...

How to avoid the "unused param" warning when overriding a method in java 1.4 ?

In this code : public class MyClass { private Object innerValue; public Object getInnerValue() { return this.innerValue; } public void setInnerValue(Object innerValue) { this.innerValue = innerValue; } } public class MyClassReadOnly extends MyClass { MyClassReadOnly(MyClass cls) { // Mak...

XSLT template overriding

Hi Everyone, I have a small question regarding XSLT template overriding. For this segment of my XML: <record> <medication> <medicine> <name>penicillin G</name> <strength>500 mg</strength> </medicine> </medication> </record> In my XSLT sheet, I have two templates in the following order: <xsl:template match=...

jQuery UI DatePicker: override today css

I am using beforeShowDay to highlight special days in my jQuery datepicker. The only way I am able to change the background is to use the '!important' tag in my css class. This works perfectly for all days except 'today'. The css does not change the background color, only the border. my css: .genEvent a { border:solid 1px #DC143C !i...

C++ function overriding

I have three different base classes: class BaseA { public: virtual int foo() = 0; }; class BaseB { public: virtual int foo() { return 42; } }; class BaseC { public: int foo() { return 42; } }; I then derive from the base like this (substitute X for A, B or C): class Child : public BaseX { public: int foo() { return ...

C#: Overriding return types

Is there way to override return types in C#? If so how, and if not why and what is a recommended way of doing it? My case is that I have an interface with an abstract base class and descendants of that. I would like to do this (ok not really, but as an example!) : public interface Animal { Poo Excrement { get; } } public class Anim...

C++ Overriding Methods

I can't figure out what is up with this. I have a Scene class that has a vector of Entities and allows you to add and get Entities from the scene: class Scene { private: // -- PRIVATE DATA ------ vector<Entity> entityList; public: // -- STRUCTORS --------- Scene(); // -- PUBLIC METHODS ---- void ad...

Overriding Rails mislav-will_paginate plugin

I'm working with the Rails mislav-will_paginate plugin to paginate my records. I want to produce the following output, regardless of whether there were multiple pages: X - Y of Z 1 - 100 of 1826 will_paginate in WillPaginate::ViewHelpers returns nil if there was only one page of records. I want to override this in the cleanest possibl...

In C++, is a function automatically virtual if it overrides a virtual function?

I would expect that if foo is declared in class D, but not marked virtual, then the following code would call the implementation of foo in D (regardless of the dynamic type of d). D& d = ...; d.foo(); However, in the following program, that is not the case. Can anyone explain this? Is a method automatically virtual if it overrides a v...

Isolating Ruby methods from overriding in subclasses? (like Java's private methods)

In Ruby, I'd like to acheive something like this Java sample: class A { private void f() { System.out.println("Hello world"); } public void g() { f(); } } class B extends A { public void f() { throw new RuntimeException("bad guy");} } public class Try { public static void main(String[] args) { new B().g();} } ...

Using all overloads of the base class

When a subclass overrides a baseclass's method, all of the baseclass's overloads are not available from the subclass. In order to use them there should be added a using BaseClass::Method; line in the subclass. Is there a quick way to inheirt the baseclass's overloads for ALL of the overridden methods? (not needing to explicitly specify ...

Quick way to locate all sub-classes that override a certain function?

I have a base class that declares a virtual function, and a large set of subclasses that inherit from the class, some of which may override the function. Now I need to alter the behavior of the base function (make it non virtual and move the overridable functionality to a different place), and I wonder if there's a quick way to locate al...

Why does an overridden function in the derived class hide other overloads of the base class?

Consider the code : #include <stdio.h> class Base { public: virtual void gogo(int a){ printf(" Base :: gogo (int) \n"); }; virtual void gogo(int* a){ printf(" Base :: gogo (int*) \n"); }; }; class Derived : public Base{ public: virtual void gogo(int* a){ printf(" Derived :: gogo (int*) \n...

Custom Class used as key in Dictionary but key not found.

I have a class, show below, which is used as a key in a Dictionary<ValuesAandB, string> I'm having issues when trying to find any key within this dictionary, it never finds it at all. As you can see, I have overridden Equals and GetHashCode. To look for the key I'm using ValuesAandB key = new ValuesAandB(A,B); if (DictionaryName.Contai...