get/sets are a waste of time and returning a reference to a private is an even bigger waste of time. If it's public, it's public and it's not a contract nor component oriented design for that class.
It's OK to make utility classes for convience sake that are not 100% to the letter modern OO designs; xsp when you waste time writing useless code to make the class less intuitive to use.
And I've always said lots of get/set tuples are a good indication of a poor design. 99% of the time they don't abstraction anything, so they do no useful work. The other 1% of the time they are poorly named mutators (methods). If it does something, give it a real function name that tells you what it does.
TCPSocket.ServerAddress = 192.168.0.1;
cout << TCPSocket.ServerAddress;
- or -
tcp_socket.connect(192.168.0.1);
cout << tcp_socket.server_address();
To me, the first way is retarded, but this is how several connection abstraction layers work (ADO comes to mind).
...
Quote:Original post by thedevdan
Wait... VC++2005 has properties?
MSVC5 did (MSVC2005 is MSVC7.2 I think) even 4 might have.
C++ Builder has had them since v1 or 2.
I think gcc even has an extention for them.
The only place they are typically used is in generated code, such as MS COM or from Borland's UI builder (and sometimes in Borland's VCL).
You can write them yourself, if you dig deep in Software Engineering I think I posted the syntax of them all about two years ago.
PS Friends are generally worse than accessors. Only useful/needed in a few case, e.g. operator overloading or extremely tightly coupled classes, such as DirectShow filters & pins.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara