让所有pimpl课程成员公开 [英] Making all members of pimpl classes public

查看:50
本文介绍了让所有pimpl课程成员公开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在创建一个库,其中几个类相互交织得很紧。

我想让它们全部使用pimpls,这样可以很容易地避免这些循环

的依赖性,而我正在考虑公开所有这些pimpl

类声明。推理是因为只有

..cc文件中的代码才需要访问它们,为什么要保护它们以便让b / b
更难以访问它们混淆了?


你对此有何看法?


-

回复,取消所有ZIG !!


备用电子邮件地址: em ****** @ asfandyarZIG。 cjbZIG.netZ IG

Hi,

I''m creating a library where several classes are intertwined rather tightly.
I''m thinking of making them all use pimpls, so that these circular
dependancies can be avoided easily, and I''m thinking of making all these pimpl
class declarations public. Reasoning is that since only the code within the
..cc file will need to ever access them, why protect them in ways that would
make access to them more difficult and obfuscated?

What are your thoughts on this?

--
To reply, take of all ZIGs !!

Alternative email address: em******@asfandyarZIG.cjbZIG.netZIG

推荐答案

Asfand Yar Qazi写道:
Asfand Yar Qazi wrote:
我是创建一个库,其中几个类紧密交织在一起。我正在考虑让他们都使用pimpls,这样可以轻松避免这些循环的依赖性


在紧急情况下使用Pimpls,作为对糟糕设计的改造。


如果您正在计划设计,请编写大量单元测试,并阅读

重构书籍,以帮助保持设计在增长时保持清洁。然后研究依赖倒置原则,并使用它来输入

只是一些抽象接口。简单测试用例的必要性

会强制存在许多这样的接口。

我正在考虑将所有这些pimpl类声明公开。
推理是因为只有.cc文件中的代码才需要访问它们,为什么要以可以访问它们的方式保护它们更加困难和混淆?
I''m creating a library where several classes are intertwined rather
tightly. I''m thinking of making them all use pimpls, so that these
circular dependancies can be avoided easily
Use Pimpls in an emergency, as a retrofit to a bad design.

If you are planning a design, write lots of unit tests, and read the
Refactoring books to help keep the design clean as it grows.

Then research the Dependency Inversion Principle, and use that to put in
just a few abstract interfaces. The necessities of your simple test cases
will force many of these interfaces to exist.
and I''m thinking of making all these pimpl class declarations public.
Reasoning is that since only the code within the .cc file will need to
ever access them, why protect them in ways that would make access to them
more difficult and obfuscated?




规则不是将所有数据成员设为私有。规则是不要在全球范围内制作原始物品。


您应该优先考虑尽可能保密。内部的事情

实施文件(.cc)已经是私有的,所以把它们变成私有的:

无关紧要。


主要处理其内容的.cc文件,与其他.cc文件相比,很少有b $ b依赖项,是连贯的。你的

..cc文件越连贯,对其他.cc文件就越有用和移动。您可以轻松地更改它,而不会影响其他.cc文件。


-

Phlip
http://www.greencheese.org/ZeekLand < - 不是博客!!!



The rule is not "make all data members private". The rule is "don''t make
primitive things globally public".

You should prefer to make everything as private as possible. Things inside
implementation files (".cc") are already private, so making them private: is
irrelevant.

A .cc file that mostly deals with its own contents, and has very few
dependencies out to other .cc files, is "coherent". The more coherent your
..cc file, the more useful and mobile it is to other .cc files. You can
change it easily without affecting other .cc files.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!


Phlip写道:
Asfand Yar Qazi写道:

Asfand Yar Qazi wrote:

我''创建一个库,其中几个类紧密交织在一起。我正在考虑让他们都使用pimpls,以便可以轻松避免这些循环依赖
I''m creating a library where several classes are intertwined rather
tightly. I''m thinking of making them all use pimpls, so that these
circular dependancies can be avoided easily



在紧急情况下使用Pimpls,作为对糟糕设计的改造。

如果您正在计划设计,请编写大量的单元测试,并阅读重构书籍,以帮助保持设计的清洁。

然后研究依赖倒置原理,并用它来放入几个抽象的接口。简单测试用例的必要性将迫使许多这些接口存在。


Use Pimpls in an emergency, as a retrofit to a bad design.

If you are planning a design, write lots of unit tests, and read the
Refactoring books to help keep the design clean as it grows.

Then research the Dependency Inversion Principle, and use that to put in
just a few abstract interfaces. The necessities of your simple test cases
will force many of these interfaces to exist.




我不认为我同意这个 - pimpl成语很容易将界面

与实现区分开来。它允许我将接口放在.hh

文件中,而不引用单个数据成员。它很容易允许

写时复制行为,并允许接口文件保持不变

即使下面的东西发生了根本性的变化。


或者你的意思是什么?


-

回复,拿走所有ZIG !!


备选电子邮件地址: em******@asfandyarZIG.cjbZIG.netZ IG


Asfand Yar Qazi写道:
Asfand Yar Qazi wrote:

我不认为我同意这一点 - pimpl成语很容易分开<来自实现的接口。

I don''t think I agree with that - the pimpl idiom easily separates
interface from implementation.




我猜你不需要pimpl来将接口与实现分开,

当然,如果你没有制作模板课。



I guess you don''t need pimpl to separate interface from implementation,
of course, if you''re not making template classes.


这篇关于让所有pimpl课程成员公开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆