JObserver: Difference between revisions
From Joomla! Documentation
New page: <span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki>
</span>
{{Description:JObserver}}
===Defined in===
l... |
m preparing for archive only |
||
| (3 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
JObserver is an abstract class which provides basic functionality to use the Observer/Observable design pattern within a Joomla Application. See also JObservable. | |||
===Defined in=== | ===Defined in=== | ||
| Line 18: | Line 15: | ||
|Method to update the state of observable objects | |Method to update the state of observable objects | ||
|} | |} | ||
===Importing=== | ===Importing=== | ||
<source lang="php">jimport( 'joomla.base.observer' );</source> | <source lang="php">jimport( 'joomla.base.observer' );</source> | ||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
namespace=CodeExample | |||
category=JObserver | category=JObserver | ||
namespace=CodeExample | |||
category=ClassExample | category=ClassExample | ||
include=* | include=* | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
Latest revision as of 01:56, 25 March 2017
JObserver is an abstract class which provides basic functionality to use the Observer/Observable design pattern within a Joomla Application. See also JObservable.
Defined in
libraries/joomla/base/observer.php
Methods
| Method name | Description |
|---|---|
| __construct | Constructor |
| update | Method to update the state of observable objects |
Importing
jimport( 'joomla.base.observer' );
Let's say, we want to integrate Error-Handling in our application, but we don't know yet, if we want the error to be display, logged in a file, stored to the database, or all of the above. Our goal is, to keep the object that raises the error independent of the objects that store the error message.
What happened here? We separated the functionality of raising an error of the functionality of handling an error. In the future you can add additional ErrorHandlers, or remove some of the existing handlers, without the need to change any classes at all. Furthermore you can simply change an Errorhandler, without the need to change the MyError class. This greatly increases the reusability of your code.
This example was originally contributed by Batch1211.