inheritance

In Django, how could one use Django's update_object generic view to edit forms of inherited models?

In Django, given excerpts from an application animals likeso: A animals/models.py with: from django.db import models from django.contrib.contenttypes.models import ContentType class Animal(models.Model): content_type = models.ForeignKey(ContentType,editable=False,null=True) name = models.CharField() class Dog(Animal): is_lucky...

Object Oriented Best Practices - Inheritance v Composition v Interfaces

I want to ask a question about how you would approach a simple object-oriented design problem. I have a few ideas of my own about what the best way of tackling this scenario, but I would be interested in hearing some opinions from the Stack Overflow community. Links to relevant online articles are also appreciated. I'm using C#, but the ...

Should I subclass List<T> or have it as a property?

Hi all, I have faced this problem quite often during the last couple of months, during which I've been building this system. The scenario is this: I have this kind of object that essentially is a list of other objects, but has some other properties specific of its nature. For example: Class Tests: Contains many Test objects Has prope...

Good reasons to prohibit inheritance in Java?

What are good reasons to prohibit inheritance in Java, for example by using final classes or classes using a single, private parameterless constructor? What are good reasons of making a method final? ...

C#: Force Compiler error on use of myObj.ToString()

I have a class that contains a bunch of properties. It is a mistake by a programmer if they call ToString() on an object of that type. Take this example code: using System; public class Foo { public int ID = 123; public string Name = "SomeName"; private string ToString() { return null; } } public class MyClass { publi...

Single Table Inheritance find issues

I have the following 3 rails classes, which are all stored in one table, using rails' Single table inheritance. class Template < ActiveRecord::Base class ThingTemplate < Template class StockThingTemplate < ThingTemplate If I have a StockThingTemplate with ID of 150 then I should logically be able to do this: ThingTemplate.find(150) =...

how to use 'super' ?

Hi, I was wondering if anyone could explain to me the difference between doing class Child(SomeBaseClass): def __init__(self): super(Child, self).__init__() and this class Child(SomeBaseClass): def __init__(self): SomeBaseClass.__init__(self) I've seen 'super' being used quite alot in classes with only sing...

How to inherit constructors?

Imagine a base class with many constructors and a virtual method public class Foo { ... public Foo() {...} public Foo(int i) {...} ... public virtual void SomethingElse() {...} ... } and now I want to create a descendant class that overrides the virtual method: public class Bar : Foo { public override void Somet...

How to correctly inherit from a usercontrol defined in XAML in Silverlight

If I have a usercontrol (in Silverlight) that I've written, that uses XAML to define it's appearance, how can I make a customised version of it? i.e. I have MyControl.xaml & MyControl.xaml.cs What do I need to do if I want a "SpecialisedControl" child class? I assume I just make a new code file, then inherit from MyControl. But what if...

Python inheritance - how to disable a function

In C++ you can disable a function in parent's class by declaring it as private in the child class. How can this be done in Python? I.E. How can I hide parent's function from child's public interface? ...

C++ Parent class calling a child virtual function

I want a pure virtual parent class to call a child implementation of a function like so: class parent { public: void Read() { //read stuff } virtual void Process() = 0; parent() { Read(); Process(); } } class child : public parent { public: virtual void Process() { //process stuff } child...

Interiting from asp:Image or asp:ImageButton?

I got this logic in a control to create a correct url for an image. My control basically needs to diplay an image, but the src is actually a complex string based on different parameters pointing at an image-server. So we decided to to create a control MyImage derived from asp:Image - it works like a charm. Now i need the same logic but ...

Problem with inheritance in C++

Here's my problem: I have a virtual method defined in a .h file that I want to call in a class that inherits from the base class. Sadly though, the method in the derived class doesn't get called. Is there a better way to implement what I'm trying to do? #ifndef ofxBASE_SND_OBJ #define ofxBASE_SND_OBJ #include "ofConstants.h...

python properties and inheritance

I have a base class with a property which (the get method) I want to overwrite in the subclass. My first thought was something like: class Foo(object): def _get_age(self): return 11 age = property(_get_age) class Bar(Foo): def _get_age(self): return 44 This does not work (subclass bar.age returns 11). I ...

Overriding a method with Generic Parameters in Java?

I have an abstract Class Monitor.java which is subclassed by a Class EmailMonitor.java. The method public abstract List<? extends MonitorAccount> performMonitor(List<? extends MonitorAccount> accounts) is defined in Monitor.java and must be overridden in EmailMonitor.java. I currently have the method overridden in EmailMonitor.java a...

Is there an easy way to use a base class's variables?

When you have a derived class, is there an simpler way to refer to a variable from a method other than: BaseClass::variable EDIT As it so happens, I found a page that explained this issue using functions instead: Template-Derived-Classes Errors. Apparently it makes a difference when using templates classes. ...

From Child instance call base class method that was overridden

Consider the following code: Public Class Animal Public Overridable Function Speak() As String Return "Hello" End Function End Class Public Class Dog Inherits Animal Public Overrides Function Speak() As String Return "Ruff" End Function End Class Dim dog As New Dog Dim animal As Animal animal = CType(dog, A...

Best practices for managing several specialized versions of one app

I have a web application that has many faces and so far I've implemented this through creating themes. A theme is a set of html, css and images to be used with the common back end. Things are laid out like so: code/ themes/theme1 themes/theme2 And each instance of the web application has a configuration file that states which theme ...

c++ class friend

Hi, I'm trying to compile such code: #include <iostream> using namespace std; class CPosition { private: int itsX,itsY; public: void Show(); void Set(int,int); }; void CPosition::Set(int a, int b) { itsX=a; itsY=b; } void CPosition::Show() { cout << "x:" << itsX << " y:" << itsY << endl; } class CCube { fri...

Removing repeated conditions using polymorphism and the Factory pattern

<?php /** * My codebase is littered with the same conditionals over and over * again. I'm trying to refactor using inheritance and the Factory * pattern and I've had some success but I'm now stuck. * * I'm stuck because I want to derive a new class from the one * returned by the Factory. But I can't do that, so I'm obviously * d...