Lets say I am creating an API for class University to create a Class.
(This Class has Class name, Teacher and students).
eg:
class Class{
..
private:
std::string class_name_;
Teacher teacher_;
std::vector<Student> students_;
};
class University{
public:
//API 1
void CreateClass(const std::string&, Teacher, std::vector<Student>);
//API 2
void CreateClass(const std::string&, Teacher);
//API 3
void CreateClass(const std::string&);
private:
std::vector<Class> classes_;
..
};
Think of Class just like normal Class that are in typical University.
Do you think it is rational to have API2 and API3? I asked this question because when I started creating class University, I started up with API1. Then during the middle of my project I realized I need API2 and API3 because, I was parsing class information from file (This file contains information on class) and I could not have all the information at one go during the parsing the file. So, I thought of creating an empty class with just a Class name first then add student and teacher latter to that specific class as I go parsing further through the file.
Another question: Is it against object oriented design principle to have Class with just
name? I ask this because normally Class have teacher and students then only its called a Class.
Also in future, some one could misuse the API3 to create a class that is empty and never bother to populate the teacher and students, this leave the Class empty.