Uncle Bob in his Clean Code says:
So all the same rules apply. Functions that take variable arguments can be monads, dyads, or even triads. But it would be a mistake to give them more arguments than that.
void monad(Integer... args); void dyad(String name, Integer... args); void triad(String name, int count, Integer... args);
So Uncle Bob suggests that no more than 3 arguments should a function get, right?
But what about CTOR arguments in class inheritance hierarchy? What if each class in hierarchy adds a new field and you should initialize them in CTOR. See an example below:
class Person
{
private:
std::string m_name;
int m_age;
public:
Person(const std::string& name, const int age);
std::string getName() const { return m_name; }
int getAge() const { return m_age; }
~Person();
};
#include "Person.h"
class Student : public Person
{
private:
std::string m_university;
int m_grade;
public:
Student(const std::string& name, const int age, const std::string& university, const int grade);
std::string getUniversity() const { return m_university; }
int getGrade() const { return m_grade; }
~Student();
};
See how student gets 4 arguments, while Person gets only 2 and Student adds two more. So how we should handle this?
Student
did not derive fromPerson
, it would still have 4 arguments. \$\endgroup\$