本文介绍了为什么立面图案+显露模块化图案“增加安全性”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据参考:下面是一个更高级的外观模式版本,为内部方法增加了安全性。

问题:
老实说他们的意思是增加安全性?而且,什么是不安全的例子?最后,对于安全性和这个外观+显示模块模式,什么是一个简单而真实的用例?

Question:Honestly what do they mean add security? Furthermore, what would be insecure example? Lastly, What would be a simple but real use case for security and this facade + revealing module pattern?

var MyModule = ( function( window, undefined ) {

  // revealing module pattern ftw
  function MyModule() {

    function someMethod() {
      alert( 'some method' );
    }

    function someOtherMethod() {
      alert( 'some other method' );
    }

    // expose publicly available methods
    return {

      // in our normal revealing module pattern, we'd do the following:
      someMethod : someMethod,

      // in the facade pattern, we mask the internals so no one has direct access by doing this:
      // HOW DOES THIS MASK THE INTERNALS?  WHAT DO THEY MEAN BY ADDS SECURITY?
      someMethod : function() {
        someMethod();
      }

    };

  }

})(window);

} )( window );

推荐答案

这只是没有意义。真的没有。

This just makes no sense. Really none.


  • 没有添加安全。开发Web应用程序时,安全性是完全不同的领域。

  • 与其他模式结合使用易于实现 真的不是一个优势。正常的设计更简单。

  • 可以轻松补丁内部。当然。但是。你真的可以介绍它,当你真的补丁内部,或外部垫片。

  • 提供一个更简单的公共接口。那么,它可以用来减少接口的复杂性,特别是如果内部方法有其他参数没有被记录,并且不被公开。但是,示例中的 someMethod 没有任何参数,所以在这里没有用。

  • There is no added "security". Security is a completely different field when developing web applications.
  • "Works well in combination with other patterns", "Easy to implement" is not really an advantage. The normal design is even simpler.
  • "Makes it easy to patch internals". Sure. But YAGNI. You still can introduce it when you really patch internals, or shim externals.
  • "Provides a simpler public interface". Well, it can be used to reduce the complexity of the interface, especially if the internal methods have additional parameters that are not documented and are expected not to be exposed. But the someMethod in the example does not have any parameters, so it's just useless here.

实际上,揭示模块模式本身就是立面。它定义了一些内部函数,然后将它们导出到模块对象上,其属性名称是外部接口。不需要额外的间接层。

Actually, the revealing module pattern already is a facade by itself. It defines some internal functions, and then exports them on the module object, whose property names are the external interface. There's no need for an additional layer of indirection.

这篇关于为什么立面图案+显露模块化图案“增加安全性”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 11:23