Search code examples
oopunit-testingterminologyencapsulation

What is the antonym of encapsulation?


Using online dictionary tools doesn't really help. I think the way encapsulate is use in computer science doesn't exactly match its meaning in plain English.

What is the antonym of computer science's version of encaspulate? More specifically, what is an antonym for encapsulate that would work as a function name.


Why should I care? Here's my motivation:

// A class with a private member variable;
class Private
{
public:
   // Test will be able to access Private's private members;
   class Test;
private:
   int i;
}

// Make Test exactly like Private
class Private::Test : public Private
{
public:
   // Make Private's copy of i available publicly in Test
   using Private::i;
};

// A convenience function to quickly break encapsulation on a class to be tested.
// I don't have good name for what it does
Private::Test& foo( Private& p )
{ return *reinterpret_cast<Private::Test*>(&p); } // power cast

void unit_test()
{
   Private p;
   // using the function quickly grab access to p's internals.
   // obviously it would be evil to use this anywhere except in unit tests.
   assert( foo(p).i == 42 );
}

Solution

  • The antonym is "C".

    Ok, just kidding. (Sort of.)

    The best terms I can come up with are "expose" and "violate".