This one class I have has only protected variable attributes like int health and int level, but no methods. Is this bad practice? I am using this for a save game function and it only needs to use variables, but requires no methods. The files look like this:
Human.h:
// Human.h - Johnny P
#pragma once
namespace SharpEngine {
class Human {
protected:
std::string name;
int level;
int health;
int defense;
int strength;
int experience;
int money;
int inventory[10];
};
}
Human.cpp
// Human.cpp - Johnny P
#include <string>
#include "Human.h"
Well, “bad practice” is a somewhat laden term.
Let’s rather say that a common pattern is “Dumb Data” where the class/struct is just there to contain the data. This is not quite the same as “Plain Old Data” (POD), which is a C-compatible struct.
Having said that, using “protected” is not typical of a Dumb Data pattern. In using “protected” you imply that you will derived from it, which then implies at the very least a virtual destructor.