multiple-inheritance

Limit of multiple inheritance in C++

不问归期 提交于 2019-12-04 17:52:01
问题 What is the limit of multiple inheritance in C++? i.e, how many classes can a class inherit from? Is it implementation dependent or is there a constraint placed on the number of classes you can inherit from in multiple inheritance? 回答1: It's implementation defined. C++11 gives recommended minimums in the Implementation quantities section of the standard: — Direct and indirect base classes [16 384]. — Direct base classes for a single class [1 024]. [...] — Direct and indirect virtual bases of

How to reuse code when multiple inheritance is not an option?

☆樱花仙子☆ 提交于 2019-12-04 17:34:41
I would like to make use of few methods from couple of my old tested classes into my new class that I am building. Unfortunately, C# does not support multiple inheritance. How do I reuse code from these old classes? Do I just create them as member objects? or Do I have any other options? Generally, using composition instead of inheritance is the way forward, yes. If you could give a concrete example of the kind of thing you mean, that would make it easier to help find the appropriate approach though: it's not always the same. Using them as member objects should be a good idea. Then you can

calling init for multiple parent classes with super? [duplicate]

点点圈 提交于 2019-12-04 16:35:45
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Can Super deal with multiple inheritance? Python inheritance? I have a class structure (below), and want the child class to call the __init__ of both parents. Is this possible to do in a 'super' way or is it just a terrible idea? class Parent1(object): def __init__(self): self.var1 = 1 class Parent2(object): def _init__(self): self.var2 = 2 class Child(Parent1, Parent2): def __init__(self): ## call __init__ of

Python decorate a class to change parent object type

柔情痞子 提交于 2019-12-04 12:13:49
Suppose you have two classes X & Y. You want to decorate those classes by adding attributes to the class to produce new classes X1 and Y1. For example: class X1(X): new_attribute = 'something' class Y1(Y): new_attribute = 'something' new_attribute will always be the same for both X1 and Y1. X & Y are not related in any meaningful way, except that multiple inheritance is not possible. There are a set of other attributes as well, but this is degenerate to illustrate. I feel like I'm overcomplicating this, but I had thought to use a decorator, somewhat likeso: def _xywrap(cls): class _xy(cls):

Java 8 doesn't provide the same solution to allow multiple inheritance which they gave to solve interface default methods

别来无恙 提交于 2019-12-04 11:54:31
Problem: We know that Java doesn’t allow to extend multiple classes because it would result in the Diamond Problem where the compiler could’t decide which superclass method to use. With interface default methods the Diamond Problem were introduction in Java 8 . That is, because if a class implements two interfaces, each defining the same default method, and the implementing class doesn’t override the common default method, the compiler couldn’t decide which implementation to chose. Solution: Java 8 requires to provide an implementation for default methods implemented by more than one interface

Qt multiple inheritance and signals

感情迁移 提交于 2019-12-04 11:46:02
问题 I'm having a problem with QT regarding multiple enheritance because of QObject. I know that a lot of others have the same problems but I don't know how I should fix it. class NavigatableItem : public QObject { Q_OBJECT signals: void deselected(); void selected(); void activated(); }; class Button : public NavigatableItem, public QToolButton { Q_OBJECT ... } class MainMenuOption : public Button { Q_OBJECT ... } When I do this MainMenuOption* messages = new MainMenuOption(); connect(messages,

Java abstract class implements an interface, both have the same method

北慕城南 提交于 2019-12-04 11:33:02
While looking at some OOP materials, I thought of this question which confused me a little bit: Consider having the following interface,abstract class, and a concrete class: package one; public interface A { void doStuff(); } package one; public abstract class B implements A { public abstract void doStuff(); } class C extends B{ public void doStuff() { } } Class C won't compile unless it provides an implementation for method doStuff() . The question here: 1-Is doStuff() method in class C an implementation to the interface A 's method, or it is for the abstract method in class B ? to be more

How to extend states from multiple classes

落花浮王杯 提交于 2019-12-04 11:22:54
(Please note: knowledge of the trading card game Magic: The Gathering will be a plus here. Sorry, I don't know how to put it any easier.) I have hit upon a problem using Java , which I'll describe as follows... I have a fundamental class called Card with all the following attributes: public class Card{ String Name; String RulesText; String FlavorText; String Cost; int ConvertedCost; String Rarity; int Number; } The Permanent class extends Card, and is extended in turn by the classes Creature, Planeswalker, Artifact, Land and Enchantment. As of yet, among them, only the first two have fields of

Understanding the exposition of Alexandrescu about the weaknesses of multiple inheritance [closed]

☆樱花仙子☆ 提交于 2019-12-04 11:02:19
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . UPDATE: I have asked a narrower question here. On pages 6-7 of Modern C++ Design , Andrei Alexandrescu gives a very fundamental discussion of the strengths and weaknesses of two C++ language features -- multiple inheritance and templates -- with respect to building flexible

Does implementing multiple interfaces violate Single Responsibility Principle?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 10:26:31
问题 From Wikipedia: Single responsibility principle states that every class should have a single responsibility, and that responsibility should be entirely encapsulated by the class. Does that mean implementing multiple interfaces violates this principle? 回答1: I would say not by itself. A class can have one responsibility, but do multiple things in the process, and implement one interface for each set of things it needs to do to fulfill its responsibility. Also, interfaces in Java can be used to