Thread: Inheritance Problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by audinue View Post
    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.)
    Last edited by tabstop; 08-15-2009 at 12:55 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance problem
    By logicwonder in forum C++ Programming
    Replies: 5
    Last Post: 10-07-2006, 10:14 AM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  3. Multiple inheritance problem
    By Magos in forum C++ Programming
    Replies: 8
    Last Post: 02-21-2006, 09:27 AM
  4. Inheritance using Stack Class Problem
    By dld333 in forum C++ Programming
    Replies: 17
    Last Post: 12-06-2005, 11:14 PM
  5. Replies: 5
    Last Post: 11-07-2005, 11:34 PM