inheritance

Why does DataMapper use mixins vs inheritance?

So I'm just curious about this: DataMapper uses a mixin for its Models class Post include DataMapper::Resource While active-record uses inheritance class Post < ActiveRecord::Base Does anyone know why DataMapper chose to do it that way (or why AR chose not to)? ...

Inheritance in C# - simple question

Duplicate In C#, why can’t a List object be stored in a List variable Here is my code: public class Base { protected BindingList<SampleBase> m_samples; public Base() { } } public class Derived : Base { public Derived() { m_samples = new BindingList<SampleDerived>();...

Solution to the lack of covariance with generics in c# 2.0 (BindingList)

It's a design question. I have a business object, and 5 business object types that are derived from it. I also will have a class which has BindingList as a member. I will have 5 classes derived from it. Since covariance doesn't work here, how would you structure the design to minimize code repetition? I could of course chuck the Bind...

Winforms UserControl is not using the inheritance tree I have created. What am I doing wrong.

Hello, I am working on a wizard form framework that will allow me easily create wizard forms. I have a WizardForm form that has a panel on it. My plan is to dynamically load UserControls into this panel on the form. Each UserControl that is loaded onto the form panel must implement certain properties (allowNavigateNext, AllowNAvigat...

XAML - How Do I Bind an Element of a Derived <UserControl> to an Element of the Base <UserControl>?

How do I bind an element of a derived <UserControl> to an element of the base <UserControl>? I have defined a UserControl called Tile as my base class. This would be an abstract base class, if XAML wouldn't balk when I tried to instantiate an object derived from it ... Anyway, so far Tile only contains a single dependency property:...

Implementing comparison using a generic interface in C++

Let's say I'm working on a library that works on items of type Item. The main entry point is a class like: class Worker { private: SomeContainer _c; public: void add( const Item &i ); void doSomething(); }; The doSomething() method looks at the added items, compares them, etc. and does something with them. So the Item class ...

Can protocols within protocols be treated as inclusive of the protocol they adopt?

I am assigning protocols in a couple classes that follow an inheritance tree. Like so: first class @protocol LevelOne - (void) functionA @end @interface BaseClass : NSObject <LevelOne> { } second class @protocol LevelTwo <LevelOne> - (void) functionB @end @interface SubClass : BaseClass <LevelTwo> { } Later I am assigning the c...

PHP Inheritance and MySQL

So I'm trying to adopt good object oriented programming techniques with PHP. Most (read all) of my projects involve a MySQL database. My immediate problem deals with the users model I need to develop. My current project has Agents and Leads. Both Agents and Leads are Users with much of the same information. So, obviously, I want a clas...

Why can't you use GetType when casting?

I asked a still unanswered question that will shed more light on this question. Why can't I do this... _wizardDialog.UIRoot.Controls.Clear() _wizardDialog.UIRoot.Controls.Add(TryCast(wizardUserControl, wizardUserControl.GetType)) Why does using GetType in this way fail. The argument for try cast are object and type. Since wizardUse...

Do subclasses allocate memory and methods of their ancestors?

In C++, when a class inherits other class, if I create an object for the subclass, then will the subclass object create memory for all data members and member functions for the superclass, too? ...

Is downcasting this during construction safe?

I have a class hierarchy where I know that a given class (B) will always be derived into a second one (D). In B's constructor, is it safe to statically cast the this pointer into a D* if I'm sure that nobody will ever try to use it before the entire construction is finished? In my case, I want to pass a reference to the object to yet ano...

Virtual base class data members

Why it is recommended not to have data members in virtual base class? What about function members? If I have a task common to all derived classes is it OK for virtual base class to do the task or should the derived inherit from two classed - from virtual interface and plain base that do the task? Thanks. ...

method hiding in c# with a valid example .why is it implemented in the framework.? what is the Real world advantage.?

Can anyone explain the actual use of method hiding in C# with a valid example ? If the method is defined using the new keyword in the derived class, then it cannot be overridden. Then it is the same as creating a fresh method (other than the one mentioned in the base class) with a different name. Is there any specific reason to use th...

OOP: retrieve 'fathers' attributes from the 'child' object.

Hi guys, here i am again ;) My problem atm is with nested php classes, i have, for example, a class like this one: class Father{ public $father_id; public $name; public $job; public $sons; public function __construct($id, $name, $job){ $this->father_id = $id; $this->name = $name; $this->job =...

jQuery val() Method on a Custom Object

I have an object called ValueBox that I created like this: function ValueBox(params) { ... $.extend(true, this, $('/* some HTML elements */')); ... var $inputBox = $('input[type=text]', this); ... this.val = function(newValue) { if(typeof newValue == "number") { $inputBox.val(newValue); $inputBo...

Java Inheritance Question

I Have something similar to this setup: public class Base { public String getApple() {return "base apple"}; } public class Extended extends Base{ public String getApple() {return "extended apple"}; } Somewhere else in the code I have this: { Base b = info.getForm(); if (b instanceof Extended){ b = (Extended) b;...

Java error: Implicit super constructor is undefined for default constructor

I have a some simple Java code that looks similar to this in it's structure: abstract public class BaseClass { String someString; public BaseClass(String someString) { this.someString = someString; } abstract public String getName(); } public class ACSubClass extends BaseClass { public ASubClass(String someS...

Constructing a generic java class where T is a class foo or a subclasses of foo

I have a class Foo with subclass SubFoo, a collection class FooListing. I want to create a generic FooListing<T> where T is either Foo or a subclass of Foo From the wording of the documentation (under 'Wildcards'), it sounds like public class FooListing<T extends Foo> { ... } ...would let me use FooListing<SubFoo>, but not FooListin...

XML schemas with multiple inheritance

Is it possible to have multiple inheritance in XML schemas, if so how? Example <xs:schema xmlns:xs="http://www.w3.org/2001/Schema" ....> <xs:complexType name="Account"> <xs:sequence> <xs:element name="balance" type="xs:decimal"/> <xs:element name="accountNo" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:c...

How to reuse code when multiple inheritance is not an option?

I would like to make use of few methods from couple of my old tested classes into my new class that I am building. Unfortunately, C# does not support multiple inheritance. How do I reuse code from these old classes? Do I just create them as member objects? or Do I have any other options? ...