J
Jayden Shui
Hi All,
I have classes which primarily collect and provide data information.
For example, the class Problem is used to define a physical problem to
be modeled. The problem has background (such as air), sources (such as
speakers at some positions), receivers (such as microphones at some
positions), and objects (such as walls, tables and chairs). I'd like
to compute the sound heard or recorded at the receivers.
My questions is how to build a good code for the class Problem? I have
a number of similar classes. I figured out several versions. Please
help me compare, give me your comments and suggestion, and your better
design for the class Problem?
// -------------- Version 1: detail all the interface functions.
----------------
class Problem
{
public:
void SetBackground();
Background const& GeBackground() const;
void AddSource(Souce const& source);
std::vector<Source> const& GetSourceVector() const;
private:
Background mBg;
std::vector<Source> mSrcVector;
};
// --------- Version 2: use macro to hide the details and code is
small --------------
#define ACCESSOR(Type, Name) ...
#define VECTOR_ACCESSOR(Type, Name) ...
class Problem
{
ACCESSOR(Background, Background);
VECTOR_ACCESSOR(Source, Source);
};
// --------- Version 3: make the attribute reference public for users
------------
class Problem
{
public:
Background& BackgroundR();
std::vector<Source>& SourceVectorR();
private:
Background mBg;
std::vector<Source> mSrcVector;
};
I appreciate your help!
Jayden
I have classes which primarily collect and provide data information.
For example, the class Problem is used to define a physical problem to
be modeled. The problem has background (such as air), sources (such as
speakers at some positions), receivers (such as microphones at some
positions), and objects (such as walls, tables and chairs). I'd like
to compute the sound heard or recorded at the receivers.
My questions is how to build a good code for the class Problem? I have
a number of similar classes. I figured out several versions. Please
help me compare, give me your comments and suggestion, and your better
design for the class Problem?
// -------------- Version 1: detail all the interface functions.
----------------
class Problem
{
public:
void SetBackground();
Background const& GeBackground() const;
void AddSource(Souce const& source);
std::vector<Source> const& GetSourceVector() const;
private:
Background mBg;
std::vector<Source> mSrcVector;
};
// --------- Version 2: use macro to hide the details and code is
small --------------
#define ACCESSOR(Type, Name) ...
#define VECTOR_ACCESSOR(Type, Name) ...
class Problem
{
ACCESSOR(Background, Background);
VECTOR_ACCESSOR(Source, Source);
};
// --------- Version 3: make the attribute reference public for users
------------
class Problem
{
public:
Background& BackgroundR();
std::vector<Source>& SourceVectorR();
private:
Background mBg;
std::vector<Source> mSrcVector;
};
I appreciate your help!
Jayden