inheritance

Inheritance - Arrays of parent class and arrays of child class - casting

I'm having trouble with inheritance. I can do what I need with single instances of the parent class and child class - as expected the methods of the parent class work fine with instances of the child class. But, I cannot see how to extend a class that uses an array of the parent class, in a way that allow me to store an array of the ...

Is multiple inheritance in Perl and Java the same?

Is the multiple inheritance in Java and Perl the same? ...

Can I create a class that is inherited from a class and from interfaces in Delphi?

I have a class TDevice. Some devices will have a cellular module. So I create an Interface IIMEI. Others devices will have an Ethernet Module. So I create an Interface IMacAddress. So, I'd like to create another class that is a child of TDevice and implements IIMEI or IMacAddress or both. Is it possible in Delphi? ...

Polymorphism Not Working Like I Thought It Would?

I have a superclass that handles car decal information. I have a subclass that handles specific decal information for a transaction. I have a special override in the transaction decal that is used to check for certain things before a decal # can be set. The problem I'm having is that sometimes I need to grab information about a generi...

How can I import global variables from a base module?

I created a module Foo::Prototype with the global variables $A and $B. I want the package Foo::Bar that uses Foo::Prototype as a base to import the global variable $A and $B. I could not figure how to do that. I understand that using global variables is not a good practice in general, but in this case I want to use them. The code looks...

Fluent interfaces and inheritance in C++

I'd like to build a base (abstract) class (let's call it type::base) with some common funcionality and a fluent interface, the problem I'm facing is the return type of all those methods class base { public: base(); virtual ~base(); base& with_foo(); base& with_bar(); protected: // whatever.....

Trying to define named_scopes and other ActiveRecord relationships on all models.

I'm trying to define a named_scope for all my models in a Rails application. Presently, I've been able to get close to this by writing an initializer for ActiveRecord::Base and putting regular methods in there. Of course, this offers no real advantage when it comes to creating query chains and is probably the least rails-ey way of getti...

Filtering a Class and Subclass in Django

I have a project with an FAQ app. The app has models for FAQ (written by the site authors) and UserFAQ (written by users-- not just a clever name). I want to return all entries, FAQ or UserFAQ that match certain conditions, but I also want to exclude any UserFAQs that don't match a certain criteria. Ideally, it would looks something like...

PHP How to distinguish $this pointer in the inheritance chain?

Please look at the following code snipped class A { function __get($name) { if ($name == 'service') { return new Proxy($this); } } function render() { echo 'Rendering A class : ' . $this->service->get('title'); } protected function resourceFile() { return 'A.res'; } } class B extends A { pr...

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

Looking for feedback on a use of the Adapter pattern.

In a project at work we have a certain value type class in our domain model that includes a very large number of attributes... public class BigValueType { private Foo foo; private Bar bar; private Baz baz; //... } We've realized that we would like to "focus" this into a number of different, somewhat more specialized c...

Can the second of two consecutively invoked stylesheets override all styles defined in the first?

If I have a HTML page that links to two stylesheets that are invoked like this: <link rel="stylesheet" href="original.css" media="screen, projection" /> <link rel="stylesheet" href="override.css" media="screen, projection" /> If these two files define the exact same style names, is it true that original.css will have no bearing on the...

Inheritance and Polymorphism conflicting in ruby on rails

Hi, I have an issue with Ruby on Rails. I have several model classes that inherit from the same class in order to have some generic behaviour. The parent class is called CachedElement. One of the child is called Outcome. I want an other model, called Flow to belong to any child of CachedElement. Hence Flow has a polymorphic attributes...

Objective-C subclass initWithSuperClass

The common Superclass of Rectangle and Circle is Shape. If I initialize some shapes, what is a good way of converting the shape into a circle later and keeping the same properties set while it was a shape? Should I implement a initWithShape in the subclasses that looks something like this? - (id) initWithShape:(Shape*)aShape { se...

Python: how to call a data member of the base class if it is being overwritten as a property in the derived class?

This question is similar to this other one, with the difference that the data member in the base class is not wrapped by the descriptor protocol. In other words, how can I access a member of the base class if I am overriding its name with a property in the derived class? class Base(object): def __init__(self): self.foo = 5 cl...

Accessing parent properties and overridden methods in PHP

I have parent and child classes as follows: abstract class ParentObj { private $data; public function __construct(){ $this->data = array(1,2,3); var_dump($this->data); $this->method(); } public function method(){ echo "ParentObj::method()"; } } class ChildObj extends ParentObj { p...

How do you serialize/deserialize a list of objects with a common root class?

Related: How can I use polymorphism in XML Serialization? I have a class I wrote for serializing the user's preferences to disk between application sessions. To read/write I'm using XmlSerializer.Deserialize() and XmlSerializer.Serialize(). One property that gets serialized is a list of sub-settings for different application compon...

What is the primary competing design pattern to concrete inheritance in application architecture?

Occasionally I'll come across comments about inheritance going "out of style" in enterprise application architecture, but I haven't come across a link to an article describing a competing theory. Also, is there a difference in implementation if the application is already built as opposed to starting from scratch? I gather this might have...

Public virtual function derived private in C++

Hello All, I was trying to figure out what happens when a derived class declares a virtual function as private. The following is the program that I wrote #include <iostream> using namespace std; class A { public: virtual void func() { cout<<"A::func called"<<endl; } private: }; class B:public A { public:...

Casting as sub-class in Actionscript

I have the following classes in ActionScript: public class A { } public class B extends A { } and these variables (in another class): public var InstanceOfA:A; public var InstanceOfB:B; How do I cast an instance of A as a class B? I tried: InstanceOfA = new A(); InstanceOfB = InstanceOfA as B; trace(InstanceOfB); I get an obj...