2

In Joomla when we develop an extension we make some class that extends another class like JModule or JPlugin and we have to use the naming convention for name it for example when we make a plugin we have to use the plg as a naming conventions for class name I am confused how this class work without make any instance of it ?

1

I assume you mean that you use the class PlgContentMyClass but then don't have to call it like so:

$foo = new PlgContentMyClass;

It because Joomla follows the observer pattern, which basically means that all subclasses (in this case PlgContentMyClass) of JPlugin will automatically register themselves to the JEventDispatcher class (which is global).

Therefore, they're automatically instantiated and you don't need to do it yourself

1

Plugin Classes are instantiated "automagically" - at the moment when Joomla triggers a Plugin Event. Depending on the Plugin event that is thrown, the respective plugin classes will get instantiated into objects and all the methods of that event name will be executed.

Joomla plugin events are triggered through the JEventDispatcher Class that implements the observer design pattern, where events are observable and the plugins are observers.

  • what about module ? does the module use any design pattern ? – hhgh4269 Jul 17 '17 at 15:37
  • 1
    @hhgh4269 - The class for a module is JModuleHelper which is also autoloaded. – Lodder Jul 17 '17 at 15:45

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.