inheritance

What are the alternatives to subtype polymorphism in scala?

I'm interested to know the complete set of alternatives to subtype polymorphism in scala. ...

How can I disable external inheritance (without classes) in C#?

How can I disable external inheritance without using classes? I know it can be done with classes like this: public abstract class NoInherit { internal NoInherit() { } } public sealed class MyType : NoInherit { /* ... */ } But not with interfaces. I don't want to use classes because I want to inherit MyType from another class and ...

What is better - polymorphism or inheritance as a concept for operating with a .net library?

If I create a library with most functions meant for overwriting, meaning that you will need to put your logic into some of initial library functions to get what you want from library. will it be normal\usual\OK? will such library be called a framework? Example In my library I have CreateData function, lots of other functions and one, le...

event driven simulation with objects

hi everyone, i am writing an event driven simulation program. i have 3 subclasses that inherit 1 base class. i need to generate those three randomly and each subclass will go through different event path (sorry its a bit hard to describe what i meant), ill give an example: let say we have a car park simulation at a mall, we have the ba...

Fluent NHibernate and automapping generic types

Hi, I'm automapping most of my model, but have a problem with generics. I've got ValueContainer, and I make it abstract so that it doesn't throw an exception during automapping. Next, I have to create classes like StringValueContainer just to make it mapped. Needless to say, I don't like this approach, since I'm perfectly happy with the...

how to fetch hierarchy of my model in rails.

This is my common model which has no table. class CommonActiveRecord < ActiveRecord::Base self.abstract_class = true def before_validation set_blank_attributes_to_nil(@attributes) end end My other models look like this .. class BalanceName < CommonActiveRecord def before_validation super end end I want to fet...

Access a private variable of the super() class in Java - JChart2D

I have extended a class in Java that has a private variable that I want to get the value of before it is changed. There are no methods to access this variable in the super class. I have tried super().m_zoomArea (the variable is in the ZoomableChart class of jChart2D). The variable is updated when the mouseDragged method is called. I have...

Abstract property inheritance and Fluent NHibernate Automapping

I thought I understood what I was doing, and I swear this used to work when I used it in my last project! I have an abstract class Enity that I use as a base class for all my DomainModel classes when working with NHibernate. The class is defined as: public abstract class Entity<TKey> where TKey : IComparable { public abstract TK...

Inheritance and templates and virtual functions ( this can get messy)

Just finding my way around templates so was trying out a few stuff. Let me know what I am doing wrong here. I am trying to overload a inherited templates virtual method. // class templates #include <iostream> using namespace std; template <class T, class A> class mypair { T a, b; public: mypair (T first, T second) {a...

How is it that U[] is castable to T[]?

It is clear that the T[] array type is not covariant as the elements of a T[] can be set by index. And yet, a U[] can be cast to a T[] without any complaints from the compiler as long as U derives from T. Man[] men = new[] { new Man("Aaron"), new Man("Billy"), new Man("Charlie") }; Person[] people = (Person[])men; In the above code i...

Virtual base members not seeing overrides?

I always thought base.Something was equivalent to ((Parent)this).Something, but apparently that's not the case. I thought that overriding methods eliminated the possibility of the original virtual method being called. Why is the third output different? void Main() { Child child = new Child(); child.Method(); //out...

How can I create a generic BaseTest with NUnit that I can inherit from and have tests from the base run?

So basically i have a domain object and a generic repository that can do CRUD operations with that object. public interface IBaseRepository<T> where T : BaseEntity { void Add(T entity); void Remove(T entity); T ById(int id); IEnumerable<T> All(); } So I have several implementations of this interface, one for each domai...

Accessing a class's properties two ways.

I'm stuck on creating a class architecture to do this: I have very many (About 78) types of block. The level for the game is made of these blocks. In the level's ByteArray, there are simply numbers, denoting the type of block. So for collision handling, I can just retrieve the number at the wanted position and get that block's propertie...

Retrieve type of base type without knowing its derived type

I need to get type of an object in base type. However I can't use BaseType, because I can't know how many levels of types the object has. class Base { public string Name { get set; } public DoAThing() { Type myType = GetType(); // returns Derived } } class Derived : Base { public int Age { get; set; } ...

How to apply a "mixin" class to an old-style base class

I've written a mixin class that's designed to be layered on top of a new-style class, for example via class MixedClass(MixinClass, BaseClass): pass What's the smoothest way to apply this mixin to an old-style class? It is using a call to super in its __init__ method, so this will presumably (?) have to change, but otherwise I'd l...

Accessing public inherited Template data members

Hi, I require some clarification on the question why do we need the scope resolution operator or this pointer to access publicly inherited members from a template base class. As I understand it is for adding clarity but then how does this add any further clarity than just point that it is a member of the class. To make my question clear...

subclassing a StreamWriter in vb.net

I'm trying to create a subclass of StreamWriter to write .CSV files, where no linebreaks are allowed in the fields. Amongst other things i replace the newline character and delimit stuff. This goes fairly well untill I try to end a line. I don't override or shadow StreamWriter.writeLine() As soon as I call writer.WriteLine() I end up...

What class does the target object take on after casting?

OK, noob question. I'm studying for the SCJP and got 3 questions on object reference casting wrong which all seem to point to the same misunderstanding. Just wanted to confirm what the right insight should be. Right, here are the questions: 1. 1. class CodeWalkFour { 2. public static void main(String[] args){ 3. Car c = ne...

Inheritance in Lift Mapper or Record Framework

Is there a way to define proper a inheritance model in Lift using Mapper o Record Framework where there is a table for the parent class and one table for each son? ...

Can I make a public member variable private in a derived class?

I want to do make a public member in a base class private in a derived class, like this: class A { public: int x; int y; }; class B : public A { // x is still public private: // y is now private using y; }; But apparently "using" can't be used that way. Is there any way to do this in C++? (I can't use private...