Thread: Question about UML.

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    88

    Question about UML.

    For this diagram:
    http://chorist.mis.ccu.edu.tw/teachi...al/final_5.jpg
    Let's talk about the class "S" and "T" only.
    Should I write like this:
    Code:
    class S{
    public:
      void setID();
      int getID();
      void printID();
    private:
       int i ;
    };
    
    class T : public S{
    protected:
      int j;
    };
    or this ?
    Code:
    class S{
    public:
      void setID();
      int getID();
      void printID();
    private:
       int i ;
    };
    
    class T : public S{
    public:
      void setID();     //  <<< different at here
      int getID();
      void printID();
    protected:
      int j;
    };
    The 'i' and 'j' are not important.
    The main point is whether I should write the functions repeatedly in the inheritance.

    My teacher give me the model answer like the second form. I am wondering because I believe that the first form is correct.

    thx.

    ref:
    '+' = public
    '-' = private
    '#' = protected
    Last edited by L.O.K.; 01-14-2005 at 01:18 AM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    There's no need to recreate the function to do the same thing, if an available function in the base class already does it. If you wanted a different "getID" function, say to add 10 to it when it returns the value, then sure, go ahead and make one. But if it's going to be simply doing the same thing it already does, there's no point.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  2. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 01:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM