I have simple question about class design in C++.
Lets assume we have the following class:
class DataBase
{
public:
DataBase();
void addEntry(const std::string& key, double value);
double getEntry(const std::string& key);
protected:
std::map<std::string, double> table;
};
There is another class which holds a pointer to an instance of DataBase class:
class SomeClass
{
protected:
DataBase *someDataBase;
};
Here I get confused, as two options come to my mind:
- Each instance of
SomeClasswill have a database of its own. In the sense that only the data added by this instance will be present in this database (dedicated databases). - Each instance of
SomeClasswill be referring to a central database. Data added by any of the instances ofSomeClasswill be in one single database (a global database).
Question:
- What is the name of the aforementioned concepts in OOP?
- How each of the aforementioned approaches can be achieved in C++