Pages

Friday, November 08, 2013

The Revealing Module Pattern

The Revealing Module Pattern, proposed by Christian Heilmann, is a slightly improved version of Module Pattern.  This makes coding easier as we don’t have to repeat the name of the main object when we wanted to call one public method from another or access public variables. Also, in the previous case (Module Pattern), we have to change the name of the private method also, if we need to make it public.

In this pattern, we would simply define all of our functions and variables in the private scope and return an anonymous object with pointers to the private functionality we wished to reveal as public.

Advantages
  • More consistent syntax
  • Eases readability
Disadvantages
  • If a private function refers to a public function, that public function can't be overridden if a patch is necessary
  • Modules are more fragile
Read more about Revealing Module Patterns ...

No comments:

Post a Comment