PHP 封装数据有什么用?
我经常一次又一次地问自己这个问题。 PHP封装数据有什么用?尽管我确实了解向公众隐藏应用程序的数据或设计实现的用法和用处。我确实同意这种方式,通过不允许其他开发人员看到我如何实现其他方法,我可以实现很多安全性。现在对于 PHP 我还有一些未解答的问题。
a) PHP 中如何封装数据 会帮助我,因为 PHP 没有 提供任何加密系统(我知道 存在很少,但我正在谈论 一般)这将加密我的源代码 代码不被其他人、任何人阅读 随时可以回来查看我的来源和 对违反规则的行为进行相应修改。 现在这奠定了整个目的 数据封装不是吗?
现在可能有不同的情况,我可能必须使用 PHP 来处理,让我考虑两种情况,根据情况我有两个交易。
情况A:
客户希望我开发一个网站 应用程序,将被存储 本地进入他的台式机并 从那里访问。在这样的背景下 这种情况我无能为力 确保没有人接触源头 代码。封装数据是没有意义的 我看到用这里。不是吗?
情况B:
我需要开发一个网络应用程序 它将托管在服务器中并且 从那里访问,我有 定义了几个有界的类 通过封装,但我想要其他 开发人员通过以下方式扩展该类 利用公共 API。我真的愿意 不知道我该如何允许 任何人(开发人员)都可以使用我的扩展 这种情况下上课吗?我真的 不确定公共 API 的情况如何 工作??如果有人的话我将不胜感激 可以阐明逻辑 实施 PUBLIC API 的背后。并且是 这就是数据封装的由来 进入图片?这是唯一的吗 我急需的情况 待实现的封装 在我的应用程序中?
谢谢。
I Often ask this question to myself again and again. what is the use of encapsulating the data in PHP. although i do understand it's usage and usefulness of hiding the data or design implementation of an application from Public. i do agree this way i could achieve lots of security by not allowing other developers to see how i implemented other methods. now in case of PHP i still have some unanswered questions.
a) How does encapsulating data in PHP
gonna help me because as PHP does not
provide any encryption system (i know
there exist few but i am talking in
general) which will encrypt my source
code from being read by others, anyone
can always comeback see my source and
modify accordingly breaking the rules.
now this lays down the whole purpose
of data encapsulation isn't it?
Now there may be different situation i may have to handle using PHP let me take into consideration two scenarios where i have two deal according to the situation.
SITUATION A :
A Clients wants me to develop a Web
Application, Which will be stored
locally into his desktop machine and
accessed from there. in the context of
this situation i can do nothing to
make sure no one touches the source
code. Encapsulating the data is of no
use here i see. isn't it?
Situation B:
I need to develop a Web Application
which will be hosted in server and
accessed from there, and i have
defined several class which is bounded
by encapsulation, but i want other
developers to extend the class by
making use of Public API. i really do
not have any idea on how i can allow
anyone(developers) to extend using my
class in this situation? i am really
not sure on how public API things
work?? i will be grateful if someone
could put some light on the logic
behind implementing PUBLIC API. and is
this where Data Encapsulation comes
into picture? is this the only
situation where i will badly need
encapsulation to be implemented
within my application?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不使用封装是因为它可以防止人们接触您的代码,而是因为您希望为您的对象创建一个有限但专用的公共 API 来交换消息。这是 OOP 范式中的关键要素。目的不是安全性而是可维护和灵活的应用程序。如果人们想修改你的代码,就让他们修改吧。他们是成年人了。
You do not use Encapsulation because it prevents people from touching your code but because you want to create a limited but dedicated public API for your objects to exchange messages through. This a key element in in OOP paradigm. The aim is not to security but maintainable and flexible applications. If people want to modify your code, let them. They are grown ups.
我相信你在这里混淆了概念。一件事是数据封装的设计原则,另一个概念是源代码或逆向工程的可用性。
数据封装对您的开发团队很重要。它的优点是,由于接口清晰,代码更可重用,并且由于数据在逻辑上分离,代码更易于阅读和理解。
这与代码可用性和对代码进行逆向工程的可能性无关。即使数据被封装,您的代码仍然可以被查看和分析。
当您发布闭源库时,这些概念就会相遇。您想要确保它有一个清晰的公共 API,作为接口提供,并且您想要确保它是加密的,这样没有人可以复制其内部结构。
I believe you are mixing conepts here. One thing is the design principle of data encapsulation, another concept is the availability of the source code or reverse engineering.
Data encapsulation is important to your development team. Its advantages are the fact that code is more reusable thanks to the clear interfaces and the code is more easy to read and understand because data are logically separated.
This has nothing to do with code availability and possibility to reverse engineer your code. Even if data are encapsulated, your code can still be viewed and analyzed.
Those concepts meet when you are publishing a closed source library. You want to make sure that it has a clear public API, provided as an interface, and you want to make sure it is encrypted so nobody can copy its internals.