inheritance

How to prevent hide or override on a public property

I have an abstract base class that has a Property on it that I would like to prevent both hiding, aka new, and override on. public abstract class DomainObject { public bool IsDeleted { get; set; } } public class BankAccount : DomainObject { public bool IsDeleted { get; set; } } The issue is: I need BankAccount to inherit from...

Can I "extend" a closure-defined "class" in Javascript?

I have a Javascript "class" defined like so: var Welcomer = function(name) { var pName = name; var pMessage = function() { return "Hi, " + pName + "!"; }; return { sayHi: function() { alert(pMessage()); } }; }; new Welcomer('Sue').sayHi(); Is there a way to "subclass" Welcomer in such a way that I can red...

Why does C++ not allow inherited friendship?

Why is friendship not at least optionally inheritable in C++? I understand transitivity and reflexivity being forbidden for obvious reasons (I say this only to head off simple FAQ quote answers), but the lack of something along the lines of virtual friend class Foo; puzzles me. Does anyone know the historical background behind this dec...

Javascript inheritance problem

I don't seem to be able to overwrite class methods correctly, using the following code ... function core() { console.log( "CORE CONSTRUCTOR CALLED" ); } core.prototype.output = function() { return 'CORE'; } function sub1() { console.log( "SUB 1 CONSTRUCTOR CALLED" ); this.core(); } sub1.prototype = core.prototype; sub...

How can I make all Core Data objects inherit from my class rather than NSManagedObject?

I created my own class that I want Core Data to use instead of NSManagedObject: @interface MyManagedObject: NSManagedObject { id delegate; } I can't use a category since this declares an ivar. All of my Core Data objects use concrete classes rather than being instances of NSManagedObject. I use the code generator to generate these f...

Java inheritance question

you have public class Question and public class MultipleChoice extends Question and public class SurveyQuestions where SurveyQuestions has private static List<Question> q = new ArrayList<Question>(); In main you keep adding questions and all the things questions are composed of to the list. Once done, you want to iterate ov...

Access to private inherited fields via reflection in Java

I founded a way to get inherited members via class.getDeclaredFields(); and acces to private members via class.getFields() But i'm looking for private inherited fields. How can i achieve this? ...

inherited factory method should return instances of own class not inherited class

I have a class that has a complex static factory method, lets call it ClassA. I have extended ClassA into ClassB and I want ClassB's factory method to do everything that ClassA's factory method does, except return a ClassB. class ClassA{ static public function Factory($construct_args, $contents){ $new = new ClassA($construct_a...

implementing a new interface without creating a derived type

Hello, I have a several C# classes called ShapeA, ShapeB, ShapeC, etc. and collection class called ShapeCollection. they all inherit from an abstract class called Geometry. All of these classes arrive from a 3rd party assembly, so I can't change them. I want too add a new method to all of these Shape classes, let's call it Paint(), and...

C++: Can a struct inherit from a class?

I am looking at the implementation of an API that I am using. I noticed that a struct is inheriting from a class and I paused to ponder on it... First, I didn't see in the C++ manual I studied with that a struct could inherit from another struct: struct A {}; struct B : public A {}; I guess that in such a case, struct B inherits f...

How can I create a base domain object with Spring Roo?

So I'm creating my domain objects for my Spring Roo app. I've got two similar domain objects that I'd like to inherit from a base object. ~.domain.LayerBase ~.domain.ColorLayer extends ~.domain.LayerBase ~.domain.ImageLayer extends ~.domain.LayerBase Is there an easy way to do this in the console or do I have to do this by hand? ...

How to setup a relationship so that more than one type of object can be in a set with Spring Roo

My domain thus far looks like: ~.domain.RenderJob ~.domain.RenderLayer ~.domain.ImageLayer extends ~.domain.RenderLayer ~.domain.ColorLayer extends ~.domain.RenderLayer I'd like to add a set field to RenderJob named 'layers'. Elements in the set can be either of type ImageLayer or ColorLayer, both of which extend RenderLayer. Is there...

.NET refactoring, DRY. dual inheritance, data access and separation of concerns

Back story: So I've been stuck on an architecture problem for the past couple of nights on a refactor I've been toying with. Nothing important, but it's been bothering me. It's actually an exercise in DRY, and an attempt to take it to such an extreme as the DAL architecture is completely DRY. It's a completely philosophical/theoretic...

Inherit active_record in rails.

Right now my classes are look like this. class BalanceName < ActiveRecord def before_validation set_blank_attributes_to_nil(@attributes) end end class Balance < ActiveRecord def before_validation set_blank_attributes_to_nil(@attributes) end end I want to inherite activer record into one class and than want...

Accessing inherited class variables in PHP

Hello, I have two classes. Looking to be able to grab a variable that is within a global object of a class. Class Order { public $number = "1234"; } Class Business { public $order; function __construct() { global $order; $order = new Order(); } } $b = new Business(); echo $b->order->number; In the cas...

simple inheritence question

Suppose there is a business function you need to implement, which sets some kind of a profile. Depending on how data is received, however, setting profile will be implemented differently. For instance parameters may be passed directly to the object which would be able to setProfile(); or, parameters would have to be discovered and ...

Problem with Inheritance.

This is a fragment from "Exceptional C++" Item 24, Solution, first bullet from the bottom of the page: Never use public inheritance to implement "IS-ALMOST-A." I've seen some programmers, even experienced ones, inherit publicly from a base and implement "most" of the overridden virtual functions in a way that preserved the semanti...

C++ Weird Diamond inheritance issue

I have this A / \ B C \ / D A has a pure virtual function, prototyped as: virtual A* clone(void) const = 0; B and C virtually inherit from A ( class B: public virtual A, class C: public virtual A) B has the virtual function, prototyped as: virtual B* clone(void) const {}; C has the virtual function, protot...

Does using prototypes in JavaScript have any real world advantages?

I just finished Doug Crockford's The Good Parts, and he offers three different ways to go about inheritance: emulation of the classical model, prototype-based inheritance, and functional inheritance. In the latter, he creates a function, a factory of sorts, which spits out objects augmented with desired methods that build upon other obj...

Discriminated unions and inheritance

Hi all, I'm looking to create a scene-graph for my F# project somthing like: root ->player_bob -->torch ->enemy_1 -->extravagant_hat -->enemies_cat_jess --->fleas --->fur_ball ->loot etc,etc. Each item needs to hold a collection of game objects to represent it's children. e.g enemy1's list contains a cat and a hat and the cats list...