Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

New GoF design pattern

Name: Anonymous 2014-04-29 4:31

CONSTIPATED ENCAPSULATION

#include <iostream>

class Anus
{
public:
Anus(int n=123):hax(&num) { num=n; }
void setNum(int n) { num=n; }
const int *const hax;
private:
int num;
} anus;

int main()
{
std::cout << *anus.hax << "\n";

anus.setNum(42);
std::cout << *anus.hax << "\n";

return 0;
}

Name: Anonymous 2014-04-29 12:39

That is just retarded. Why not just make num be public? Then no need for stupid setter and the code would be more clean. If you later need to add setter (actually needed in 0.001% of use cases), just refactor all the code using Anus, it's not that a big deal.

Name: Anonymous 2014-04-29 14:45

>>6
Most of the time, yes, it is retarded. Sometimes it is useful (those 0.001%)

Name: Anonymous 2014-04-30 8:51

>>8
We could make the change transparent to the user
That indicates you are making a library API. Of course, the API should use encapsulation and give access only to the needed bits. Because in case of library, we might not be able to refactor the using code (if we don't have access to user's code). But that's maybe the 0.001% of the code out there that needs to concern itself with this shit.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List