Is it a good object-oriented-design practice to send a pointer to private data to another class?

Posted by Denis on Stack Overflow See other posts from Stack Overflow or by Denis
Published on 2010-03-19T21:50:06Z Indexed on 2010/03/19 21:51 UTC
Read the original article Hit count: 540

Hello everyone,

There is well known recommendation not to include into class interface method that returns a pointer (or a reference) to private data of the class.

But what do you think about public method of a class that sends to another class a pointer to the private data of the first one. For example:

class A  
{  
public:
    void fA(void) {_b.fB(&_var)};  

private:  
    B   _b;   
    int _var;  
};

I think that it is some sort of data hiding damage: the private data define state of their own class, so why should one class delegate changes of its own state to another one? What do you think?

Denis

© Stack Overflow or respective owner

Related posts about object-oriented-design