Would this sort of implementation violate the principle of data hiding for OOD? In other words, does returning a const iterator or const reference to map violate the principle of data hiding? |
The idea of returning an iterator was yours. The
const
limits the access via the iterator, i.e. is "hiding" more.
Overall, if you do hand out
map<string, int>::iterator
to client, the client sees that you have at least
map<string, int>
. A relational database could have multiple tables (maps) and a query can combine data from those tables.
In that sense the Thomas Approach is superior. The class Report has no idea how the class A stores its data. The Report simply gets pieces of data for output formatting.
The A could have "premade queries":
1 2 3 4 5
|
class A
{
vector<T> q1( const string& key );
// more q's
}
|
Each query generates a list of results somehow. The user (B) does not know how data was copied to the result. The Ts could be int, tuple, ...