inheritance

How do I implement inheritance using iBatis for Java?

Please point me to an example! iBatis documentation doesn't cover this. I have been struggling all morning getting my discriminator and subMap to work! ...

How method hiding works in C#? (Part Two)

The following program prints A:C(A,B) B:C(A,B) (as it should) public interface I { string A(); } public class C : I { public string A() { return "A"; } public string B() { return "B"; } } public class A { public virtual void Print(C c) { Console.WriteLine("A:C(" + c.A() +...

Why do I get a segmentation fault when calling a virtual method in this code?

I'm still learning C++; I was trying out how polymorphism works and I got a segmentation fault when calling a virtual method. (Note: I didn't mark the destructor as virtual, I was just trying out to see what happens.) Here's the code: #include <iostream> using namespace std; class Base { protected: char *name; public: Base(char ...

What's the right way to check for inheritance from a class/interface?

The code below is looping through a dictionary of strings and IMyCompanySettings looking for values that implement IMyCompanyProductSetting. Clearly, trying to cast and raising an exception is a very expensive way to do this. public static List<IMyCompanyProductSetting> GetProductSettings(ConfigurationManager cfm) { List...

Should a business object collection inherit from Collection<T> when it doesn't extend it?

I have a business object collection (representing data from the database) that inherits from Collection and has a static method that calls a stored proc and then populates its properties with the data returned. My question is; is it wrong to inherit from Collection as it doesnt really extend the class? or would it be better to not inher...

Anonymous vs named inner classes? - best practices?

I have a class, let's call it LineGraph, that renders a line graph. I need to subclass it, but the derived class is only used in one place and is coupled to the class that uses it. So I am using an inner class. I see two ways to do this: Anonymous inner class public class Gui { LineGraph graph = new LineGraph() { // extra ...

extending an existing flex component

Hi, this is a pretty basic question but I can't seem to get it right. If I want to extend an existing component, what is the right way to do it? For example, this thread talks about it, but doesn't give an example: http://stackoverflow.com/questions/710646/flex-datechooser-events-for-individual-days A simple example of just adding a tr...

Problem in Model inheritance when some elements are deleted

I use a snippet in http://www.djangosnippets.org/snippets/1034/ for my Model inheritance. It works fine at the first. However, after I delete some elements in database, the code works wrong. As I debug, I found that the problem is reside in the method: as_leaf_class. In the following code: if (model == Meal): return self return mode...

Java composition question

A question about composition and object orientation: I am trying to implement more features for a class (Java TreeMap as an example). public class TreeMap<K,V> extends AbstractMap<K,V> implements NavigableMap<K,V>, Cloneable, Serializable Using composition is the way to go on this, so I would have to create first a reusable ...

Modelling different usertypes in a relational database

Hi all.. First of all, I'm sorry about the feedback-nature of this question. I'm trying to generalize it as much as I can so others can gain from it as well, but I don't really have anyone to give me feedback on this design, so I hoped you guys could help me. With that being said, I wan't to model different usertypes in my database. I ...

Sticky situation where accessing parent functions is necessary in Java

I've been working on an economy simulator in Java and ran into a roadblock. I have an Economy class that owns a vector of Traders. Every iteration, the Economy class calls each Trader to update() and decide what trades it would like to place. The update() function returns the desired transactions to be added to the queue in the parent Ec...

What is the best way to customise parts of an existing Perl program for multiple customers?

I have an existing Perl application which is deployed to multiple customer sites. Unfortunately, the code has been cloned multiple times to customise it for individual customers. So there are now several complete copies of the code which all have slight (or major) differences. My task is to fix this mess by creating a single, generic co...

Internal and external interfaces and collections

What would be the best way to implement the following? I have a collection of objects that implement an interface, internally I want to be able to expose set and get on the properties and externally only get. Here's an example of the sort of thing I want... That does't compile. public interface ITable { string Name { get; } } inte...

How did I break inheritance?

Refactored from bug_report_view.cc and bug_report_view.h, I extracted send_report(), report_phishing(), a few other smaller functions and BugReport::Cleanup into bug_report.cc and bug_report.h (my versions). Compiling now, I get: [...]bug_report.cc:196: error: no matching function for call to ‘URLFetcher::URLFetcher(std::wstring&, UR...

Inheritance vs Specialization

Considering the following two usage scenarios (exactly as you see them, that is, the end-user will only be interested in using Vector2_t and Vector3_t): [1]Inheritance: template<typename T, size_t N> struct VectorBase { }; template<typename T> struct Vector2 : VectorBase<T, 2> { }; template<typename T> struct Vector3 : VectorBase<T, ...

How to structure this interface/inheritance

I have a File class that has an Open() method. I have a subclass of File called TextFile that implements an IReadableFile interface, which requires the implementation of a Read() method. If I declare a variable myFile as IReadableFile, I can't call the Open() method on it. I want to be able to exercise the functionality of TextFil...

C++/Java Inheritance vs. Delegation vs. etc...

Hello, I am creating a class library with many different options for possible customizations. For example, you can design your class so that it can perform FeatureX(), or you can design your class so that it can perform FeatureY(). Under normal circumstances, you would simply create an interface IFeatureX with a pure virtual method cal...

Polymorphism or Inheritance in JSON with Java and Ruby

For context, we are storing most of our data as JSON strings. This works very well with Hadoop on the backend and is easy to handle in Ruby on the front end. My data types fit the natural pattern for inheritance. For simplicity, lets say I have a class Pet and a process FeedPet that feeds a pet. I also have a process WalkDog that only a...

Composition vs Inheritance for Equality & Hashcode providers

When comparing entities and aggregate roots I use an ABC, which I borrowed from Oren Eini: Generic Entity Equality. For value objects I was equally ingenious. I used Jimmy Bogard’s Value Object ABC: Generic Value Object Equality Now my question is; should I be favouring inheriting these ABCs or should I perhaps be using the generic equa...

Prohibit direct extension of Java class outside its package

I have a package with a public abstract class Player { /*...*/ } and these public abstract class GamePlayer extends Player { /*...*/ } public abstract class TournamentPlayer extends Player { /*...*/ } public abstract class StatelessPlayer extends Player { /*...*/ } Users of the package need Players but in order to use the package w...