Questions tagged [multiple-inheritance]
The multiple-inheritance tag has no summary.
53 questions
2
votes
1
answer
144
views
Decorate class which inherits from concrete class(es)
In my project I have several "basic" interfaces whose behavior is fixed, i.e. the default implementation will always be good for every puropse. So I defined them as concrete classes with ...
18
votes
8
answers
14k
views
Why is "diamond problem" a problem? Why doesn't the child simply call both parent's methods sequentially? Why is a thing with solutions a problem?
I know there have been many post about diamond problem, one of it: Why do you reduce multiple inheritance to the diamond problem?. But I'm not asking what it is or what is the solution of the problem. ...
0
votes
0
answers
589
views
What is the Best Practice for handling multiple Entities that behave identically?
Because I have multiple entities with unique fields, I need multiple repositories for each one even though each Entity will be handled exactly the same. What is the best way to handle these separate ...
-1
votes
1
answer
878
views
What is the use of Multiple Inheritance in languages like C++ and Python?
C++ and Python are the only two languages I know supporting multiple Inheritance. Other object oriented languages I have seen like Java and Ruby do not support multiple inheritance. Even the front-end ...
0
votes
1
answer
72
views
Select inheritance hierachy at run time
I want to model a machine with a class machine. By the way the architecture of the project has been built, the module that defines each machine is its own directory.
So in directory manufacturer/...
0
votes
1
answer
87
views
"Subtractive" behaviour extension vs overriding a function completely - what are the pros/cons?
Lets imagine some vendor code that we want to extend on our project level
protected function getDefaultFormClasses() {
return [
new FormClassA(),
new FormClassB(),
new ...
2
votes
1
answer
318
views
Selective method inheritance
I have a lot of classes that are just a CRUD interface for microservices. They only have a param for the endpoint and some of the methods get_list / get_item / create / update / delete / activate / ...
6
votes
3
answers
9k
views
Interfaces in Python, multiple inheritance vs. a home-made solution
I am writing a Python framework. In order to ensure a class has some properties, I make base "interface" classes like:
class BananaContainer:
def __init__(self):
self._bananas = []
@...
2
votes
1
answer
268
views
Using virtual inheritance for an interface system based on abstract classes
I want to use a physics engine (like bullet or PhysX) in my program, however I want to hide the actual physics engine from it, so I can easily swap it out with another during run-time (e.g. switch ...
2
votes
1
answer
368
views
Approach for implementing Device and Protocol layers in C++?
I'm writing a program that will interface with an external device. It will support numerous devices that may use different communication interfaces like USB, serial, etc.
This is what I have so far:
...
2
votes
4
answers
5k
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 ...
18
votes
2
answers
19k
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
3
answers
157
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
1
answer
115
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
1
answer
157
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 ...
6
votes
1
answer
2k
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
2
answers
737
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
2
answers
6k
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
2
answers
6k
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
4
answers
3k
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
3
answers
19k
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 ...
13
votes
4
answers
4k
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,...
9
votes
2
answers
939
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 ...
11
votes
1
answer
2k
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 ...
4
votes
1
answer
2k
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 ...
20
votes
1
answer
3k
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
3
answers
2k
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
1
answer
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
2
answers
326
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 to ...
3
votes
1
answer
322
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. ...
0
votes
2
answers
668
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 ...
26
votes
9
answers
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 ...
3
votes
4
answers
6k
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
4
answers
4k
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
3
answers
1k
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 ...
66
votes
1
answer
13k
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 ...
10
votes
2
answers
12k
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 ...
20
votes
2
answers
20k
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
1
answer
1k
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
1
answer
498
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 ...
155
votes
9
answers
45k
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
1
answer
12k
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
1
answer
488
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
2
answers
6k
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
2
answers
8k
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
1
answer
1k
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 ...
16
votes
5
answers
11k
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 ...
23
votes
7
answers
4k
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 ...
2
votes
2
answers
3k
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 ...
8
votes
1
answer
6k
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 ...