Originally Posted by
CornedBee
It's legal, and yes, it breaks encapsulation, which is why it's generally discouraged.
How would you avoid it (if possible) in the following (stupid) sample:
Code:
class HouseDataBase
{
public:
HouseList getHousesWithOpenDoors() const;
setDoorClosed(int house_id);
...
};
class City
{
HouseDataBase mHdb;
public:
HouseDataBase& getHouseDb();
...
};
int main()
{
City city;
...
city.getHouseDb().setDoorClosed(5);
...
}
Would you propagate the complete interface of the owned class HouseDb through class City? This could be a lot of (redundant) work (imagine more composition Classes like Streets, traffic lights, Cars,...)
Thank you!