封装的反义词是什么?

发布于 2024-10-01 11:04:13 字数 1038 浏览 6 评论 0原文

使用在线词典工具并没有真正的帮助。我认为封装在计算机科学中的使用方式并不完全符合其简单英语的含义。

计算机科学版本的 encasulate 的反义词是什么?更具体地说,封装的反义词是什么,可以用作函数名称。


我为什么要关心?这是我的动机:

// 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 );
}

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 );
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

顾铮苏瑾 2024-10-08 11:04:13

反义词是“C”。

好吧,开个玩笑。 (有点。)

我能想到的最好的术语是“暴露”和“违反”。

The antonym is "C".

Ok, just kidding. (Sort of.)

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

牛↙奶布丁 2024-10-08 11:04:13

封装背后的目的是隐藏/覆盖/保护。反义词是揭示/暴露/公开。

The purpose behind encapsulation is to hide/cover/protect. The antonym would be reveal/expose/make public.

海未深 2024-10-08 11:04:13

解囊怎么样..

虽然它不是一个计算机科学术语,但在医学科学中,手术去除胶囊或包膜..查看这里..

How about Decapsulation..

Though it aint a computer science term, but in medical science, Surgical removal of a capsule or enveloping membrane.. Check out here..

阳光的暖冬 2024-10-08 11:04:13

老实说,“移除/破坏封装”是我见过的最接近的事情。

如果你从英语的意义上思考这个词,封装的意思是封装在某物中。但在 CS 意义上,存在保护级别的概念,并且看起来您也想暗示规避访问级别,因此“提取”之类的内容并不能真正传达您正在寻找的含义。

但如果你只考虑访问级别,看起来你正在公开某些东西,那么“公开”怎么样?

"Removing/Breaking encapsulation" is about the closest thing I've seen, honestly.

If you think of the word in the English sense, to encapsulate means to enclose within something. But in the CS sense, there's this concept of protection levels and it looks like you want to imply circumventing the access levels as well, so something like "extraction" doesn't really convey the meaning you're looking for.

But if you just think of it in terms of what the access levels are, it looks like you're making something public so, how about "publicizing"?

云醉月微眠 2024-10-08 11:04:13

这不是一个简单的问题 - Scott Meyers 有一篇有趣的文章此处展示了封装的一些细微差别。

我将从妙语开始:如果
你正在编写一个函数,可以是
作为会员或作为
非朋友非会员,你应该
更喜欢以非会员身份实施
功能。这个决定增加了
类封装。当你想
封装,你应该想到
非成员函数。

This is not such a simple question - Scott Meyers had an interesting article to demonstrate some of the nuances around encapsulation here.

I'll start with the punchline: If
you're writing a function that can be
implemented as either a member or as a
non-friend non-member, you should
prefer to implement it as a non-member
function. That decision increases
class encapsulation. When you think
encapsulation, you should think
non-member functions.

尬尬 2024-10-08 11:04:13

“坏主意”怎么样?

How about "Bad Idea"?

ぽ尐不点ル 2024-10-08 11:04:13

“封装”的真正反义词是“全局状态”。

The true antonym of "Encapsulation" is "Global State".

梅倚清风 2024-10-08 11:04:13

封装的一般反义词是耦合,我们经常谈论紧耦合松散耦合的系统。

您希望封装组件的原因是因为它可以更轻松地推理它们的工作方式。

以火车为例:将有轨车耦合的后果是驾驶员必须考虑整个火车的特性(惯性、长度)。

但显然,我们耦合系统是因为我们需要它们协同工作。

反向封装和数据结构

我一直在挖掘另一个术语,这就是我遇到这个问题的原因,它指的是非标准风格的数据结构。

标准封装风格的示例为 Java的LinkedList;列表的实际节点被设计为消费者无法访问。理论上,这是一个实现细节,可以更改以提高性能,而现有代码将继续运行。

另一种风格是经典的功能性缺点列表。这是一个单链表,其想法是它非常简单,数据结构没有什么需要改进的,例如,

data  [a]  =  [] | a : [a]  deriving (Eq, Ord)

-- Haskellers then work directly with the list
-- There's nothing to hide because it's so simple
typicalHaskell :: [a] -> b
typicalHaskell [] = emptyValue
typicalHaskell h : t = h `doAThing` (typicalHaskell t)

这就是 来自 Haskell 标准前奏的定义,尽管报告指出这不是有效的 Haskell 语法,并且实际上 [a] 是在编译器内部定义的。

然后就是我所说的“倒置”数据结构,但我仍在寻找正确的术语。我认为这实际上与封装相反。

Python 的 heapq 模块 就是一个很好的例子。这里的数据结构是一个二叉堆,但没有 Heap 类。相反,您会获得对通用 Python 列表进行操作的函数集合,并且您负责正确使用这些方法以确保维护堆不变量。

The general opposite of encapsulation is coupling and we often talk about systems that are tightly coupled or loosely coupled.

The reason you'd want components to be encapsulated is because it makes it easier to reason about how they work.

Take the analogy of trains: the consequence of coupling the railcars is that the driver must consider the characteristics (inertia, length) of the entire train.

Obviously, though, we couple systems because we need them to work together.

Inverted encapsulation and data structures

There's another term that I've been digging for, which is how I came across this question, that refers to a non-standard style of data structures.

The standard style of encapsulation is exemplified by Java's LinkedList; the actual nodes of the list are designed to be inaccessible to the consumer. The theory is that this is an implementation detail and can change to improve performance, while existing code will continue to run.

Another style is the classic functional cons-list. This is a singly linked list, and the idea is that it's so simple that there's nothing to improve about the data structure, e.g.

data  [a]  =  [] | a : [a]  deriving (Eq, Ord)

-- Haskellers then work directly with the list
-- There's nothing to hide because it's so simple
typicalHaskell :: [a] -> b
typicalHaskell [] = emptyValue
typicalHaskell h : t = h `doAThing` (typicalHaskell t)

That's the definition from Haskell's standard prelude though the report notes that isn't valid Haskell syntax, and in practice [a] is defined in the guts of the compiler.

Then there's what I'm calling an "inverted" data structure, but I'm still looking for the correct term. This is, I think, really the opposite of encapsulation.

A good example of this is Python's heapq module. The data structure here is a binary heap, but there isn't a Heap class. Rather, you get a collection of functions that operate on generic Python lists and you're responsible for using those methods correctly to ensure the heap invariants are maintained.

月亮邮递员 2024-10-08 11:04:13

“意大利面”怎么样?

How about "spaghetti"?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文