Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [multiple-inheritance]

The tag has no usage guidance.

0
votes
4answers
587 views

Avoiding vtable pointers in objects in C++

In my previous question, it was highlight that implementations of C++ such as GCC must store a vtable pointer in every copy of a class for each parent class which has a virtual function. So a class ...
4
votes
2answers
1k views

Should a trait refer to parent methods?

Is it a code smell if the methods in my trait refer to parent::methods or to methods that are assumed to be in the utilising class? A random (senseless) example trait foo { public function bar() ...
0
votes
0answers
107 views

Is it a valid OOP design for Python?

I have following class design (not exact but you can get the idea): WRITE_METHODS = ('POST', 'PATCH') class CanPOST(BasePermission): def has_permission(self, request, view): return ...
0
votes
3answers
114 views

Separated implementations or one with all functionalities

I am currently creating Excel import modules for some complex data. I didn't plan it well and I have met code reuse issues. I have made first modules and I realized that next modules will need some ...
1
vote
1answer
83 views

Client to application interaction results in fat interfaces

How do you handle fat interfaces? Here is an example: public class TSP { public AddEmployeeContribution(...) {...} public AddMatchingContribution(...) {...} public CalculateTotal() {...} ...
-1
votes
1answer
90 views

What would be the best option in this scenario?

I have a statement. I know the ups and downs of both Composition and Inheritance, but I am unable to realize that what would be the best option the given scenario. SCENARIO: A Software company is ...
4
votes
1answer
837 views

Access methods from two interfaces's implementation in a Class

I am trying to implement the following pattern in a Cache layer. I'm splitting the implementation of possible Cache methods such as getUsers() in UserCache Class, getLikes() in PostsCache class. But ...
3
votes
2answers
344 views

Correct way to extend a hierarchy tree

I have the following tree currently to be implemented in Java. My problems are the following: How can I go about addressing the fact Admin needs to have all tier 4 logic from both branches of the ...
-2
votes
2answers
2k views

Separate interface from implementation

What is the meaning of separating interface from implementation in C++? And also what is implied by interface and implementation?
1
vote
2answers
2k views

share method logic along classes without inheriting from abstract class

In some languages (e.g. C#) a class can only ever have 1 base class which seems like a problem for what I'm trying to do. I will give you an example of what i'm trying to do, hopefully this will make ...
1
vote
4answers
2k views

Why doesn't java allow multiple inheritance of classes when it allows multiple inheritance of interfaces? [duplicate]

I am currently perusing through Jdk 8 and I came across the feature where you have multiple interfaces that overlap with the same method signature for a default method, the compiler will throw an ...
0
votes
3answers
633 views

What to do if I need more than one base class in C#? [closed]

Let's say I have a grid with square fields. For the fields I have an abstract Field class. This class has several subclasses, for example EmptyField or RoadField. Some of these fields can be connected ...
10
votes
4answers
2k views

Parallel hierarchies - partly same, partly different

There are quite a few similar questions out there 1, 2, 3, 4, but non seems exactly the case in this question, nor do the solutions seem optimal. This is a general OOP question, assuming polymorphism,...
10
votes
2answers
553 views

Is Python's inheritance an “is-a” style of inheritance or a compositional style?

Given that Python allows for multiple inheritance, what does idiomatic inheritance in Python look like? In languages with single inheritance, like Java, inheritance would be used when you could say ...
9
votes
1answer
1k views

Using Python's Method Resolution Order for Dependency Injection - is this bad?

I watched Raymond Hettinger's Pycon talk "Super Considered Super" and learned a little bit about Python's MRO (Method Resolution Order) which linearises a classes "parent" classes in a deterministic ...
2
votes
1answer
588 views

Why do you reduce multiple inheritance to the diamond problem?

Whenever I read something like this: Many programmers exhibit a slight, involuntary shudder whenever multiple inheritance is mentioned. Ask them to identify the source of their unease and they ...
19
votes
1answer
2k views

Why not make a language with mixin-only inheritance? [duplicate]

It seems that in all class-based or prototypal OOP languages, mixins are either an afterthought or a secondary feature. However, to me it looks like traditional inheritance is just a specific case of ...
0
votes
3answers
1k views

Multi inheritance in Java

Let's say I've got a generic java class Filter<InputType, OutputType> which receives an input object and transforms it to an output object. Now I've got two other classes (NoInputFilter<...
5
votes
1answer
3k views

JavaScript extend vs mixin

After having read Eric Elliott's Fluent JavaScript article, I was and still am toughtful about the way to play with instance prototypes. On one side, you have the extending inheritance... var B = ...
4
votes
2answers
248 views

Is there any harm in having classes made up mostly of inherited classes?

Say I have a few base classes: HasPosition supplies a 2D location, and methods to "move". IsDisplayable defines how a class will be displayed in a given graphics library (say, curses), and methods ...
2
votes
1answer
206 views

Language support for (syntactic) delegation in Java

Composition over inheritance is an old trend or even accepted state of the art in object oriented programming. It would be even easier to use in Java, if there were language support for delegation. ...
1
vote
2answers
289 views

The reason for scala not supporting Multiple Inheritance [closed]

I've searched around for a long time now and haven't come up with any official reason why scala doesn't support multiple inheritance. I know traits solve a lot of things, but the developers of C# for ...
25
votes
9answers
4k views

What is different between the internal design of Java and C++ that lets C++ have multiple inheritance? [duplicate]

It's drilled into the newbie Java programmers that Java (pre-Java 8) has no multiple class inheritance, and only multiple interface inheritance, because otherwise you run into diamond inheritance ...
1
vote
4answers
3k views

Implements > extends, but what about variables?

It's preferable to write programs that depend on interfaces rather than on superclasses, but what if you want a class to have certain variables? Sometimes you want a class to implement a certain ...
11
votes
4answers
2k views

Alternatives to multiple inheritance for my architecture (NPCs in a Realtime Strategy game)?

Coding isn't that hard actually. The hard part is to write code that makes sense, is readable and understandable. So I want to get a better developer and create some solid architecture. So I want to ...
1
vote
3answers
656 views

UML Class Diagram: How can I represent “orthogonal” generalizations (or multi-inheritence)?

I try to represent in a UML Class Diagram the following object and features: The Object: A System (e.g. an electronic device) that can be of Type A, B or C If the System is of type A, it has a ...
50
votes
1answer
9k views

How are mixins or traits better than plain multiple inheritance?

C++ has plain multiple inheritance, many language designs forbid it as dangerous. But some languages like Ruby and PHP use strange syntax to do the same thing and call it mixins or traits. I heard ...
7
votes
2answers
6k views

Code re-use in C++, via multiple inheritance or composition? Or…?

I originally asked this question on StackOverflow, but I was directed here, and I think my problem is perhaps as much conceptual as technical, so here goes. If you’re defining a hierarchy of abstract ...
16
votes
2answers
11k views

How do Traits in Scala avoid the “diamond error”?

(Note: I used 'error' instead of 'problem' in the title for obvious reasons.. ;) ). I did some basic reading on Traits in Scala. They're similar to Interfaces in Java or C#, but they do allow for ...
-1
votes
1answer
935 views

Size of objects during Multilevel inheritance [closed]

Below is a pseudo declaration for a multilevel inheritance. Base class ( protected int data) derived1 : virtual public base ( protected int data1 ) derived2 : virtual public base ( protected int ...
0
votes
1answer
326 views

C# LinqExtensions implement multiple inheritance

According to WikiPedia "Some languages do not support mixins on the language level, but can easily mimic them by copying methods from one object to another at runtime, thereby "borrowing" the mixin's ...
120
votes
9answers
24k views

Is there any “real” reason multiple inheritance is hated?

I've always liked the idea of having multiple inheritance supported in a language. Most often though it's intentionally forgone, and the supposed "replacement" is interfaces. Interfaces simply do ...
4
votes
1answer
10k views

Adding base-class (inherited) functionality to classes that you don't control

I have a set of classes from a 3rd party library. These classes use an inheritance structure to share logic. I would like to add a layer of abstraction in the middle of their inheritance tree to add ...
7
votes
1answer
327 views

Term for a Class with Multiple Interfaces

Say I have a class that implements multiple interfaces. I pass the same instance around using a different interface, depending on what the consumer is interested in. I am trying to remember what this ...
5
votes
2answers
4k views

Python multiple inheritance or decorators for composable behaviours

I recently discovered (or rather realised how to use) Python's multiple inheritance, and am afraid I'm now using it in cases where it's not a good fit. I want to have some starting data source (...
13
votes
2answers
6k views

How does C++ handle multiple inheritance with a shared common ancestor?

I'm not a C++ guy, but I'm forced to think about this. Why is multiple inheritance possible in C++, but not in C#? (I know of the diamond problem, but that's not what I'm asking here). How does C++ ...
3
votes
1answer
991 views

Can Objective C categories serve the same purpose as Traits do in Scala?

The statement of the question seems little abstract to me, so please read the details below. Since the time when C++ was the first choice Object Oriented Language for almost anything, we had a big ...
15
votes
5answers
9k views

Proper workaround for multiple inheritence in Java (Android)

I have a conceptual problem with a proper implementation of code which seems require multiple inheritance, that would not be a problem in many OO languages, but as the project is for Android, there ...
18
votes
6answers
2k views

Does multiple inheritance violate Single Responsibility Principle?

If you have a class which inherits from two distinct classes, does not this mean that your subclass automatically does (at least) 2 things, one from each superclass? I believe there is no difference ...
1
vote
2answers
2k views

Replacing Multiple Inhertance with delegation

I was going through "Object Oriented Modelling and Design" by James Rumbaugh et al and it said that in languages where multiple inheritance is not supported like Java three mechanisms can be used as ...
7
votes
1answer
4k views

Rails - to use STI or not…that is the question

Six months ago, I asked a question about modeling data for my app, and received some advice pointing me towards STI (see Rails data model - best practices question for the details). I played around ...
4
votes
2answers
7k views

What are the pros and cons of multiple inheritance? [closed]

What are the consequences of allowing multiple inheritance in a programming language? What characteristics of multiple inheritance create an environment such that the use of multiple inheritance ...
0
votes
1answer
467 views

How to layout class definition when inheriting from multiple interfaces

Given two interface definitions ... IOmniWorkItem = interface ['{3CE2762F-B7A3-4490-BF22-2109C042EAD1}'] function GetData: TOmniValue; function GetResult: TOmniValue; function GetUniqueID: ...
14
votes
7answers
3k views

Multiple inheritance use cases

Java omits multiple inheritance on the grounds that it obviates the design goal of keeping the language simple. I wonder if Java (with its eco-system) is really "simple". Python is not complex and ...