inheritance

Long inheritance hierarchy

a 夏天 提交于 2020-01-16 04:49:05
问题 I have very long class inheritance hierarchy. For example: -MyAbstractObject --MyAbstractUiObject ---MyAbstractTable -----MyAbstractPageableTable -------MyAbstractScrollableTable ---------MyAbstractStateblaTable etc... I read at Code complete that ideal inheritance deep is 3. And sometimes it allowable to make inheritance deep 7-9. But I have inheritance deep 11! How I can change my architecture? What design pattern is applicable to my case? And what is bad is that I can change places of

C# Activator createInstance for extending class

笑着哭i 提交于 2020-01-16 00:58:07
问题 I have a base class, which is as follows: public Data() { id = num++; SetVariables(); } //fill every Variable varNames, parseInduction, noise, seperator in Children Classes public Data(String line) { //first declare all variables in sub classes if (id == 0) throw new NotSupportedException("You are not allowed to use this constructor for creating the first instance!"); id = num++; SetVariables(); parseLine(line); } And i also have a Sub Class extending this Class. class DienstGruppe : Data {

How to resolve the diamond issue in PHP?

怎甘沉沦 提交于 2020-01-16 00:06:40
问题 I have searched for solutions to the diamond problem but the only one I have found is using traits which I can't use in my case, so I'm asking here to see if anyone has an alternative solution. I have a base class Controller (I cannot change this class) and have two subclasses SecurityController and DevController . Each of these subclasses introduces methods which also use methods inside the base class. I then have a final class ApplicationController which, ideally, would extend both

How to resolve the diamond issue in PHP?

£可爱£侵袭症+ 提交于 2020-01-16 00:06:09
问题 I have searched for solutions to the diamond problem but the only one I have found is using traits which I can't use in my case, so I'm asking here to see if anyone has an alternative solution. I have a base class Controller (I cannot change this class) and have two subclasses SecurityController and DevController . Each of these subclasses introduces methods which also use methods inside the base class. I then have a final class ApplicationController which, ideally, would extend both

how to initialize an object of subclass with an “existing object of superclass” in objective-C

筅森魡賤 提交于 2020-01-15 14:45:47
问题 I have subclassed NSException class to create CustomException class. Whenever I catch an exception in code (in @catch), i want to initialize an object of CustomException (subclass of NSException) with the object of NSException that is passed as a parameter to @catch. Something like this @catch (NSException * e) { CustomException * ex1=[[CustomException alloc]initWithException:e errorCode:@"-11011" severity:1]; } I tried doing it by passing the NSException object to the init method of

Inheritance between clr project dlls

五迷三道 提交于 2020-01-15 11:44:07
问题 I have an abstract base class which is written with c++/cli. This class is located in a project. And i have other projects which inherit the abtract base class. So, the structure is like the following. Base Project: public ref class Base abstract { // implementation virtual CommonFunc(); }; public delegate void Foo(); Derived Project A: public ref class A : public Base { // implementation }; Derived Project B: public ref class B : public Base { // implementation }; And, so on. I can call both

How to access protected field of a super class in java from subclasses?

旧城冷巷雨未停 提交于 2020-01-15 11:30:07
问题 I want to access a protected field of a super-class from a sub-class in Java: Class Super { protected int field; // field set to a value when calling constructor } Class B extends Super { // field of super class is set to value when calling // constructor } Class C extends Super { // same here } B b = new B(); C c = new C(); b.super.field ? 回答1: The class can access the field directly, as if it were its own field. The catch is that the code doing the access must be in the code of the derived

How can I organise this Go code that redefines methods from an embedded type to be less redundant and more maintainable?

久未见 提交于 2020-01-15 10:14:47
问题 I have some example code in which I declare a type foo with some methods which call each other (say: foo.get , which is called by foo.double and foo.toString ). I have another type, bar , which embeds foo and redefines get . I am forced to redefine double and toString on bar , so they can see bar.get (rather than only foo.get ), but the body of these functions is basically identical to the original. Is there a better way to organise this code, to avoid the redundancy while still having bar

Inherit and overload default constructor

為{幸葍}努か 提交于 2020-01-15 09:10:08
问题 I've been searching for this and I'm amazed I haven't found anything. Why can't I inherit a base class constructor using using declaration and add an overload in the derived class? I'm using Visual C++ 2013, the base class constructor is ignored when default-constructing b : error C2512: 'B' : no appropriate default constructor available I've dealt with this by re-defining the constructors, but I don't like that. This is just a minimal example, it wouldn't bother me if I had only one base

MATLAB field access with inheritance modifying all instances?

◇◆丶佛笑我妖孽 提交于 2020-01-15 09:01:21
问题 I'm trying to develop a data structure for a mesh using the MATLAB OOP functionalities. Long story short, I'm modifying a field from an instance that inherits from the same base class as another instance, and both instances are being modified, as if the field was declared static! I have this code inside an abstract base class (m_element) in MATLAB: properties(Access = protected) nodes = containers.Map('KeyType','int64', 'ValueType', 'any'); faces = containers.Map('KeyType','int64', 'ValueType