inheritance

Force execution of parent's method before child's method without explicit call

Hi, I'm working on a c++ app and I'm facing a problem: I have a class B derived from the abstract class A that has some event handling methods. A third class C is derived from B and must reimplement some of B methods. Is there a way to implicitly call B's method before calling C's one? Class diagram: class A { virtual void OnKeyPr...

How do I limit overriding in a hierarchy?

Hi, This is an example, I'm just curious as to how it would be achieved. I want to enable only subclasses of Animal to be able to set the number of legs that they have, but I still want them to be able to set their own colour. Therefore, I want to restrict classes further down the hierarchy from then altering this Legs property. publi...

Setting subclass primary key as auto_increment using JPA 2 annotations

Hi. I'm trying to generate a database schema for my project using hbm2ddl. I'm using JPA 2 annotations to specify how the schema should look like. Right now I'm having some issues with inherited id's. I have an abstract super class, let's call it AbstractSuperClass, which looks like this: @Entity @Inheritance(strategy=InheritanceType....

Is it possible to use a MapView without having to extend MapActivity?

Currently in my design I've got a base abstract class that all of my activities extend from, however I discovered recently that in order to use a MapView you need to make your activity extend MapActivity. Since Java does not have multiple inheritance I was wondering if there is any way I can use a MapView without having to recreate my d...

AutoMapper and inheritance - How to Map?

Hi! Have this scenario: Public class Base { public string Name; } Public Class ClassA :Base { public int32 Number; } Public Class ClassB :Base { Public string Description;} Public Class DTO { public string Name; public int32 Number; Public string Description; } I have an IList<Base> my maps are: AutoMapper.Mapper.Crea...

Should I add a type column to design inheritance in postgreSQL?

I am planning to create a web application using spring/hibernate. How should I design my postgresql database in order to support inheritance? Assume that I have the following tables: super_table, sub_table_1, sub_table_2. Then sub_table_1 and subtable_2 would inherit super_table. Should I add a type column (like a char or int) so that ...

Why use inheritance at all?

I know the question has been discussed before, but it seems always under the assumption that inheritance is at least sometimes preferable to composition. I'd like to challenge that assumption in hopes of gaining some understanding. My question is this: Since you can accomplish anything with object composition that you can with classical...

Sending message to child from parent

I have class Child inherited from class Parent. What I want is to send message to child, which has implementation of that message. So it's like calling pure virtual function from parent. If I send message now from Parent I'll get warning that Parent may not respond to this message. It is true, because only Child has implementation of it....

Scala abstract method is null in superclass when subclass implements it using val?

I found an error in my scala code, which puzzles me. Below is a simplified version of the problem. In the constructor of an abstract class, I want to check a few asserts about the abstract methods. Thus when an object of a subclass is made, these asserts are checked, to see if all is implemented as it should. It goes wrong when the sub...

Object Oriented scope and inheritance in Android activity classes

I'm still very new to Object Oriented programming and am having problems with the class inheritance and the scope of variables from one instantiated class to another. I'm trying to build an android application that can read multiple XML feeds and save them to the phone's SQLite database. Each feed has a different name ("news", "audio_mi...

Problem with prototypal inheritance and instance array

I use prototypal inheritance and want to have objects with instance arrays. So if I derive some objects from one object with an instance array and access the array, all of them share the array. I want to push something to the array and only change the array in the actual object, not in all others. What is a elegent solution to this Prob...

Disallow fields in descended class C++

Hello StackOverflowers, With a friend, we had following problem recently. There was a base class: class A { public: A() : foo(10) {} virtual int getFoo() const { return foo; } protected: int foo; }; A friend implemented a class deriving from the one above. class B : public A { public: void process() { foo = 666; } p...

Can I use a category to override a method which is itself in category on the superclass?

@interface MySuperclass : NSObject { } @end @interface MySuperclass (MyCategory) - (void)myMethod; @end @interface MySubclass : MySuperclass { } @end @interface MySubclass (MyOtherCategory) - (void)myMethod; @end Is it defined which implementation of -myMethod will be called? Kochan states in Programming in Objective-C that...

xcode4 save derived class

Hi all... I'm trying to use xcode4 beta and I have this problem... In the xcode3, in the interface builder, you can set a new name for the class and after on the menu choose to save the class into new files, to allow to write some personal code... In xCode4 how can I do this?? in the properties of the object I wrote the new name of the c...

CoreData Entity Inheritance

Consider that i have two entities with following relationship: Entity A <-->> Entity B (one-to-many and inverse) Now consider that i have another entity Entity C that contains all the attributes of Entity B and some others, with following relationship: Entity A <-->> Entity C (one-to-many and inverse) Now i can improve the architec...

Silverlight: Can I set an event to a base class event handler in XAML?

I have created a custom user control to use as a base class for some maintenance functions. I would like to be able to wire up some events to handlers defined in the base class. I can do this manually in the code behind but would like to assign them in XAML. Is this not possible? <src:CustomerMaintenanceControlBase x:Class="ProjectMana...

Problem implementing generic interface

I have a base DLL which defines some basic structure and operation for a key concept within our business. This dll is then included in specific web services for each vendor that implement the specific business rules for interacting with that vendor. (While the basic concepts are the same the implementations are very different and can cha...

indexes needed for table inheritance in postgres?

this is a fairly simple question, but it's one i can't find a firm answer on. i have a parent table in postgres, and then several child tables which have been defined. a trigger has been established, and the children tables only have data inserted if a field, say field x, meets a certain criteria. when i query the parent table with ...

How to have my derived class only accept a specific derived type of another object

I have a couple different custom backup programs and I want to combine them into a single one. Doing so, I'm working on my OO design to help keep the driving program simple and easy to follow by abstracting my server and database information. I'm using two different hosts (Discount ASP.net and Rackspace). Both of them go about their bac...

Public static methods - a bad sign?

I've just read this article here: http://hamletdarcy.blogspot.com/2008/04/10-best-idea-inspections-youre-not.html, and the last bit in particular got me thinking about my code, specifically the advice: What in the world is a public method doing on your object that has no dependency on any fields within the object? This is certainly a...