inheritance

Overriding constants in derived classes in C#

In C# can a constant be overridden in a derived class? I have a group of classes that are all the same bar some constant values, so I'd like to create a base class that defines all the methods and then just set the relevant constants in the derived classes. Is this possible? I'd rather not just pass in these values to each object's cons...

How to inherit from std::ostream?

I've been googling around and I just can't find a simple answer to this. And it should be simple, as the STL generally is. I want to define MyOStream which inherits publicly from std::ostream. Let's say I want to call foo() each time something is written into my stream. class MyOStream : public ostream { public: ... private: void ...

Why can't I inherit static classes?

I have several classes that do not really need any state. From the organizational point of view, I would like to put them into hierarchy. But it seems I can't declare inheritance for static classes. Something like that: public static class Base { } public static class Inherited : Base { } will not work. Why have the designers of t...

Manipulating with pointers to derived class objects through pointers to base class objects

I have this code to represent bank: class Bank { friend class InvestmentMethod; std::vector<BaseBankAccount*> accounts; public: //... BaseBankAccount is an abstract class for all accounts in a bank: class BaseBankAccount { public: BaseBankAccount() {} virtual int getInterest() const = 0; virtual int getInve...

How does OOP manage to 'include' classes stored in different files

I'm trying to move into OOP development and am turning to here as I'm sick of searching the web and finding only the very basic information about what classes are and how they can inherit from each other - that I understand. What I don't understand as yet is how all these classes can be stored in different files, doted around a folder s...

Python base clase method call: unexpected behavior

Why does str(A()) seemingly call A.__repr__() and not dict.__str__() in the example below? class A(dict): def __repr__(self): return 'repr(A)' def __str__(self): return dict.__str__(self) class B(dict): def __str__(self): return dict.__str__(self) print 'call: repr(A) expect: repr(A) get:', repr(A...

Basic question on refactoring into a abstract class

This may be a beginner question but is there a standard way to refactor the duplication of the Wheel property into the abstract class yet still maintain the explicit cast to the Part type. Let’s assume we have to prevent a FastCarWheel from being put on a SlowCar, and that there are many properties just like this one. abstract class Car...

Force invocation of base class method

The following code when run obviously prints out "B1/A2/B2". Now, is it possible for it to print "A1/A2/B2" instead (i.e. A#method2() should invoke method1() on A, not on B)? Note: I have no such need to get pass polymorphism, this question is out of curiosity only. class A { public void method1() { System.out.println("A1"...

Inherit comments from interface or base

Hi, I noticed that in Java(doc) there exists something like @inheritDoc, so that comments from the nearest inheritable class are explicitly copied. Does there exist something like this in .Net? I know this can be achieved with GhostDoc. The downside with GhostDoc is that changes to "base" comments are not manifested... ...

extend a user control

Hello guys, I have a question about extending a custom control which inherits from UserControl. public partial class Item : UserControl { public Item () { InitializeComponent(); } } and I would like to make a control which inherits from Item sg like that public partial class ItemExtended : Item { publ...

WCF Additional Proxy Classes

I have a WCF webservice that has the following service contract [ServiceContract(Namespace = "http://example.org")] public interface IEquinoxWebservice { [OperationContract] Guid Init(); [OperationContract] List<Message> Dequeue(Guid instanceId); [OperationContract] void Enqueue(Guid instanceId, Message message...

ActiveRecord Inheritance with Different Database Tables

I have just started investigating using more advanced models in Rails. One that I use regularly, with great success, is model where a many-to-many cross-reference relationship is accessed by a class that itself is a sub-class of the base class in the many-to-many relationship. This way the cross-reference class can act as a stand-in for...

Can you inherit a sub new (Constructor) with parameters in VB?

In the code below I recieve the compile error "Error Too many arguments to 'Public Sub New()'" on the "Dim TestChild As ChildClass = New ChildClass("c")". I do not recieve it on "TestChild.Method1()" even though they are both on the base class I am inheriting from. Public Class BaseClass Public ReadOnly Text As String Public Sub...

ruby: can I have something like Class#inherited that's triggered only after the class definition?

#inherited is called right after the class Foo statement. I want something that'll run only after the end statement that closes the class declaration. Here's some code to exemplify what I need: class Class def inherited m puts "In #inherited for #{m}" end end class Foo puts "In Foo" end puts "I really wanted to have #inherit...

Why is 'textField' not instantiated when I subclass TextArea in Flex?

I'm experimenting with TextArea and inheritance to implement some additional functionality on the protected textField property. Unfortunately, when I create a new instance of the subclass, this property is set to null. I'm probably misunderstanding the way super() works, but I thought it would have been instantiated after the construct...

Can I guarantee the order in which static initializers are run in Java?

I have a Set class (This is J2ME, so I have limited access to the standard API; just to explain my apparent wheel-reinvention). I am using my set class to create constant sets of things in classes and subclasses. It sort of looks like this... class ParentClass { protected final static Set THE_SET = new Set() {{ add("one"); ...

Derive from specialized generic types

Is it possible to derive a class from a specialized generic type: TGenericBase <T> = class // ... end; TSpecializedDerived = class (TGenericBase <String>) // ... end; Just wondering if this is possible at all... EDIT Code works fine when I put it in a new project. Must be due to some other mistake; sorry about that ...

Extending the html schema

I'm trying to create a templating engine not too synactically far from ASP.net WebForms. I want the markup to look like this: <ext:Templates xmlns:ext="http://www.myschema.com/" xmlns="http://www.w3.org/1999/xhtml"&gt; <ext:Template name="Template1"> <div id="someid" style="display:none" ext:extendedAttr="someValue"> ...

Question inheriting from List(of T) class

I want to implement a priority queue class. When an item is added at a higher priority it is pushed to the front of the queue instead adding to the end of queue. Simple few lines of code Public Class PriorityQueue(Of T) Inherits List(Of T) Private _list As New List(Of T) Public Sub Enque(ByVal item As T, Optional ByVal pu...

How to perform common post-initialization tasks in inherited Python classes?

The initialization process of group of classes that share a common parent can be divided into three parts: common part1, class-specific part, common part2. Currently the first two parts are called from the __init__ function of each child class, but the second common part has to be called separately For example: class BaseClass: def ...