Originally Posted by
audinue
The first Node is plain Node without automatic linking which Linked one do.
However LinkedNode "is-a" Node which automate the link process (which technically adding new processes which may or may not required by the client).
Their behaviour is totally different even though they are the same (polymorphism).
And their responsibilities is quiet enough clear to be separated with such relationship.
If you say so, I guess. What you say above makes no sense to me (I have no idea what "automate the link process" could mean, even a little bit), but if there's a difference between the two in your code that doesn't appear in what you're showing us, then fine.
In that case, however, something like this would follow OOP style:
Code:
virtual void setNext(Node *next) {
if (next) {
next.setPrevious(this);
}
this.next = next; //this means that your choice of parameter names sucks
}
Presumably the call to next.setPrevious is okay here and won't get us into a big old loop, since you claim that Nodes don't do automatic linking, so presumably it won't try to also set the next pointer of our current object otherwise we'll be here all day.
EDIT TO ADD: Also, this means that if Node *next is actually something derived, then we will probably do the right thing by calling the override function instead of the base-class function. (Although, as mentioned, if next is really a LinkedNode, we will be in an infinite recursion kind of thing, which is another reason why I don't think your class design makes sense.)