-
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
-
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.