def*_*ode 10 oop unit-testing encapsulation terminology
使用在线词典工具并没有多大帮助.我认为封装的方式在计算机科学中的使用并不完全符合它在简单英语中的含义.
计算机科学版本的反义词是什么?更具体地说,什么是封装的反义词,它将作为函数名称使用.
我为什么要在乎?这是我的动机:
// 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 );
}
Run Code Online (Sandbox Code Playgroud)
cdh*_*wie 20
The antonym is "C".
Ok, just kidding. (Sort of.)
The best terms I can come up with are "expose" and "violate".
The purpose behind encapsulation is to hide/cover/protect. The antonym would be reveal/expose/make public.