Consequences of changing inheritance to virtual?

I'm working on a huge project that I didn't start. My task is to add some additional functionality to what already is there. I'm in a situation where I have to use virtual inheritance because I have a diamond model. The situation is depicted in the f...
more »

2017-03-23 15:03 (4) Answers

Caching attributes in superclass

I have a class which caches some values to avoid computing them many times, for instance class A(object): def __init__(self, a, b): self.a = a self.b = b self._value = None @property def value(self): if ...
more »

2017-03-20 22:03 (1) Answers

Base and derived classes C++

A few days ago, I wanted to dive into the C++ world. I'm studying the base and derived class concepts. Could someone explain the nuance going on with the following two code snippets? class A { private: virtual int GetValue() { return 10;...
more »

2017-03-20 17:03 (2) Answers

interface Interface<T> : T

Let's say I have this structure of classes and interfaces: interface IService {} interface IEmailService : IService { Task SendAsync(IMessage message); } class EmailService : IEmailService { async Task SendAsync(IMessage message) { ...
more »

2017-03-20 11:03 (1) Answers

SQL - Select instance type

I am using Oracle DB and I have this type: CREATE TYPE t_foo AS OBJECT (a VARCHAR2(20)) NOT FINAL; And also these subtypes CREATE TYPE t_foo1 UNDER t_foo() NOT FINAL; CREATE TYPE t_foo2 UNDER t_foo() NOT FINAL; I have a table of type t_foo wher...
more »

2017-03-19 16:03 (1) Answers

About Inheritance and super()

Given the code: class Character(): def __init__(self, name): = name = 50 self.damage = 10 class Warrior(Character): def __init__(self, name, weapon, armor): super(Character).__init__() ...
more »

2017-03-19 12:03 (1) Answers

Covariance in inheritance

I have a super class SheetBuilder and many sub classes that inherit this class. The super class has an abstract method that all the classes inherit. protected abstract void printResults(String abc); Now I want to overload the same method with a d...
more »

2017-03-17 08:03 (1) Answers

Class that should not be instantiated

I want to create a class hierarchy in which I have a class Block which can be instantiated by itself. Then I have a class List which inherits from Block and contains methods common to all lists, and finally I have classes OrderedList, LableledList et...
more »

2017-03-16 15:03 (4) Answers

Java Inheritance on the fly

Let ClassA represent an abstract class. I'm wondering if it's possible to do something like this in Java: public static abstract class ClassA { abstract void foo(); } private ClassB extends ClassA a = new ClassA() { // define abstract met...
more »

2017-03-16 07:03 (3) Answers

How to overcome C# List<generic<T>> constraint

I have the following situation: I have several Event classes that share common behaviour like StartEvent and StopEvent. I also have a special class each Event class works with (like pickups and you need to collect all of them to finish the event) So...
more »

2017-03-15 16:03 (2) Answers

Java: inheritance and arrays, and their children

Java: Simple question... why can I not use array[0].childMethod? Notice that myList.method() works, but when stored in an array, method() becomes unusable. Any help is appreciated. public class Main { public static void main(String[] args) { ...
more »

2017-03-11 10:03 (6) Answers

Extend HashMap and LinkedHashMap at the Same Time?

I want to extend HashMap to add the method putIfGreaterThan which basically retrieves the value for a given key and if the new value is greater than the old value we update the old value with the new value. Like this: public void putIfGreaterThan(...
more »

2017-03-10 19:03 (3) Answers

Calling Qt Dialog class from Qt MainWindow class

I have a class of my main code which uses a QtMainWindow. This calls another class MessageClass that creates a QtDialogBox: class MainClass(QtGui.QMainWindow,MainGUI.Ui_MainWindow,DialogBox.Ui_Dialog): def __init__(self): super(self.__class...
more »

2017-03-08 22:03 (0) Answers

Use a derived class automatically

I work on TTY communication with different protocols. I started to implement some code in C++ with classes. A parent class contains some basic functions (write, read...) with some virtual functions. Each protocol is a child class with specific functi...
more »

2017-03-03 11:03 (1) Answers

Nested Generics while supporting inheritance

So I have a container type generic object I'm using that looks like this: public class Property<T> { T Value { get; set; } } I want to be able to do lists of Property of different generic types, so I did this: public class Property { ...
more »

2017-03-03 01:03 (0) Answers

How to make variable exclusive to class?

Lets say this is my code: class Cat: def __init__(self): self.purs = True self.hasFur = True class HairlessCat(Cat): def __init__(self): Cat.__init__(self) jeffery = Cat() bob = HairlessCat() how can I make it so ...
more »

2017-03-01 07:03 (1) Answers