Answer the question
In order to leave comments, you need to log in
Does multiple inheritance violate OOP?
If you do not take into account any particular language, but argue in terms of programming,
then what does multiple inheritance look like in the canons of OOP?
Please explain using your painful example - there is a Node class with the next, prev methods and there is a
Task class with its execute. There is also a List class with inserter, Node removeNode.
And now I want to get a class that implements the behavior of both Task and Node. This is fine?
That is, in fact, I want to implement a third class, a collection or, in my case, List, which
will operate with task nodes, but until it becomes a node itself. That is, it
will be the main node for its children, but on a global scale it will be an ordinary leaf.
But since I have all the task sheets, the node itself must also be a task. Here's how it looks
from the OOP side and from the multiple inheritance side ?
In my case, this is not even multiple inheritance, but a multiple implementation of the
INode, ITask and IList interfaces ( IList, this is a very strong word, because there is another interface that provides one set method, in the implementation of which the passed object is inserted into the current this. next = method to be set).
What do you say?
For clarity, a little code...
interface INode {
next: INode
prev: INode
}
interface ITask {
execute(): void;
}
interface ISet {
insert(target: INode): void;
};
class SomeClass implements INode, ITask, ISet{
next: INode;
prev: INode;
execute():void {}
insert(target: INode):void
{
// и здесь просиходит установка таргета
this.next = target;
target.prev = this;
}
}
Answer the question
In order to leave comments, you need to log in
And now I want to get a class that implements the behavior of both Task and Node. This is fine?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question