Designing generic type inheritance hierarchy

I have now put another rephrased version of original question as requested by the user in the comments with class names mimicking real world scenario of postal office (though I dont know how real world the rephrased example is). Original question had...
more »

2017-07-17 17:07 (0) Answers

Overlapping java-like interfaces in C++

I've read on many places that Java's interface can be 100% emulated using C++'s abstract class with all pure virtual methods. I'm trying to convert this piece of java code: interface A { void a(); } interface B extends A { void b(); } cla...
more »

2017-07-04 09:07 (2) Answers

The this keyword is undefined in React base class

I have a basic React app and I'd like to put some commonly used functionality into a base component class and have all my other components inherit from that class to get access to those features. I have this: export class BaseComponent extends React...
more »

2017-06-29 20:06 (2) Answers

CakePHP implement custom interface

I want to create an abstract class that will inherit from an interface and then create two more classes that will inherit from this abstract class. All of this files are in a subfolder 'ExportSynthese' in the 'Controller' folder. I managed to create...
more »

2017-06-19 16:06 (0) Answers

C# Casting Generic Child Type to Parent

Let's say we have these types: class A {} class B : A {} class X<T> {} Why we can't do this? X<A> var = new X<B>(); Is there any workaround available? [Edit] I tried to use covariance but it failed because I want to access a...
more »

2017-06-18 14:06 (2) Answers

Class cross referencing?

I come from a C++ background and I am a bit lost without the whole pointer concept in python. Or at least it's unclear. For instance, I want to create a game of tick tack toe using OOP in Python. I have a couple classes like so: class Game(object): ...
more »

2017-06-18 01:06 (1) Answers

Java return only attributes of superclass

I am trying to create an API controller with java and spring boot. I want to return specific objects as JSON from specific API endpoints, nothing special so far. Now I have a child class A and a parent class B. B is abstract and A is not abstract, bu...
more »

2017-06-17 11:06 (0) Answers

Confused with generics and subtyping

So, let's say we have a simple interface public interface ICopyable<T> { void copyFrom(T original); } Which basically adds a copyFrom method with a parameterized type. And you have an interface extending it: public interface ISomeObjec...
more »

2017-06-16 18:06 (0) Answers

Constraint on method parameters to enforce type

I have a situation where I have a base class and several derived classes. I would like to have a method that can operate on an item and a list of the same class type. I was receiving a compiler error because the type of item and list within the Proce...
more »

2017-06-16 15:06 (0) Answers

C++: Class within another class as type?

could someone explain me this kind of "inheritance" which can be found in class Y: private? class X { private: char c_; public: X(char c) : c_(c){} }; class Y { private: X x_; // What is this ? public: Y(X x): x_(x){} }; int main() { X m...
more »

2017-06-15 18:06 (1) Answers

Why is the id same for these two objects?

In the below code, why is the id of parent and child the same? Should they not be different? class Parent: def __init__(self): print(id(self)) class Child(Parent): def __init__(self): print(id(self)) super().__init__...
more »

2017-05-26 15:05 (1) Answers