inheritance

In Java, how to I call a base class's method from the overriding method in a derived class?

Hello everybody, I have two Java classes : B, which extends another class A, as follows : class A { public void myMethod() { /* ... */ } } class B extends A { public void myMethod() { /* Another code */ } } I would like to call the A.myMethod() from the B.myMethod(). I am coming from the C++ world, and I don't know ho...

Inheriting from a UserControl in WPF

I am fairly new to WPF and I am having a problem with inheriting from a user control. I created a User Control and now I need to inherit from that control and add some more functionality. Has anyone does this sort of thing before? Any help would be greatly appreciated. Thank you ...

Inheritance vs. Aggregation

There are two schools of thought on how to best extend, enhance, and reuse code in an object-oriented system: Inheritance: extend the functionality of a class by creating a subclass. Override superclass members in the subclasses to provide new functionality. Make methods abstract/virtual to force subclasses to "fill-in-the-blanks" when...

Why should I declare a virtual destructor for an abstract class in C++?

I know it is a good practice to declare virtual destructors for base classes in C++, but is it always important to declare virtual destructors even for abstract classes that function as interfaces? Please provide some reasons and examples why. ...

Problem with class design and inheritance in Flash AS3.

I have problems with how to design some classes. I have three classes. One superclass, and two subclasses. One subclass (AnimatedCharacter) is made by flash, and is used to display the object on screen. The other (CharacterPhysics) is made by myself to extend the superclass. The problem is that the object I use, is of the type Animate...

How do I hide a method so it's not called by programmers but still usable in code?

I have a class called 'Ship' and a class called 'Lifeboat' Lifeboat inherits from Ship. Ship contains a method called Validate() which is called before save and it has an abstract method called FurtherValidate() which it calls from Validate. The reason this is in place is so when you call validate on the base it also validates the clas...

How to parse logs written by multiple threads?

I have an interesting problem and would appreciate your thoughts for the best solution. I need to parse a set of logs. The logs are produced by a multi-threaded program and a single process cycle produces several lines of logs. When parsing these logs I need to pull out specific pieces of information from each process - naturally this i...

Initializing a class using superclass initializer

Hello! I have got two classes, one a subclass of the other (say Animal and Dog). The superclass has got some initializers (say initAnimal), the subclass has some initializers (say initDog). The problem is that it is perfecly legal (from the compiler’s viewpoint) to do something like Dog *adog = [[Dog alloc] initAnimal], ie. initialize a ...

Can I a implement DisposeBase abstract class?

Is there a catch or hidden problem in using a DisposableBase base class instead of recoding the Dispose pattern on every class? Why aren't everyone using such a relevant class? Edits: I naturally only meant classes that implement IDisposable I know it uses up the option for inheritance, but I'm willing to pay the price (at least when...

Is Inheritance really needed?

I must confess I'm somewhat of an OOP skeptic. Bad pedagogical and laboral experiences with object orientation didn't help. So I converted into a fervent believer in Visual Basic (the classic one!). Then one day I found out C++ had changed and now had the STL and templates. I really liked that! Made the language useful. Then another day...

How do I use composition with inheritance?

I'm going to try to ask my question in the context of a simple example... Let's say I have an abstract base class Car. Car has-a basic Engine object. I have a method StartEngine() in the abstract Car class that delegates the starting of the engine to the Engine object. How do I allow subclasses of Car (like Ferrari) to declare the En...

Getting the name of a child class in the parent class (static context)

Hi everybody, I'm building an ORM library with reuse and simplicity in mind; everything goes fine except that I got stuck by a stupid inheritance limitation. Please consider the code below: class BaseModel { /* * Return an instance of a Model from the database. */ static public function get (/* varargs */) { //...

Shallow Copy From Inherited Classes

Ok so I have an abstract base class called Product, a KitItem class that inherits Product and a PackageKitItem class that inherits KitItem. ie. Product KitItem : Product PackageKitItem : KitItem I have my KitItems loaded and I need to load up a collection of PackageKitItems which are, effectively, shallow copies of KitItems. Currentl...

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...

Is it correct to inherit from built-in classes?

Hello, I want to parse an Apache access.log file with a python program in a certain way, and though I am completely new to object-oriented programming, I want to start doing it now. I am going to create a class ApacheAccessLog, and the only thing I can imagine now, it will be doing is 'readline' method. Is it conventionally correct to i...

Encapsulation VS Inheritance - How to use a protected function?

In OOP languages like C# or VB.NET, if I make the properties or functions in a super class protected I can't access then in my Form, They can only be access in my class that inherits from that super class. To access those properties or functions I need to make them public which defeats encapsulation on re-write them in my class which de...

C++: Derived + Base class implement a single interface?

In C++, is it possible to have a base plus derived class implement a single interface? For example: class Interface { public: virtual void BaseFunction() = 0; virtual void DerivedFunction() = 0; }; class Base { public: virtual void BaseFunction(){} }; class Derived : public Base, public Interface { ...

How to force a Descendant class to either use directly the Ancestor method or have a new implementation not calling inherited?

We have the TAncestor class which has a virtual method GetFile. We will have some TDescendant = class(TAncestor) which may override GetFile. We want to insure that in such a case those overriden methods do not call inherited in their implementation. But if they don't implement GetFile and just use the one from TAncestor, it's fine. Is th...

Should I extend this class or just use it?

I am writing helper classes for a large project in PHP and I have written a class called Command. It is essentially an OOP wrapper around running system commands from PHP in a controlled way. It has methods like addOption() to add -a type options and addArgument() to add other arguments. I will need to do a lot of scp'ing of files aro...

In C#, can I know in the base class what children inherited from me?

Hi, I have a problem. I have a base class vehicle and some children classes like car, motorbike etc.. inheriting from vehicle. In each children class there is a function Go(); now I want to log information on every vehicle when the function go fires, and on that log I want to know witch kind of vehicle did it. example: public class vehi...