Difference between revisions of "JObservable"
From Joomla! Documentation
m (→Examples: fixing) |
|||
Line 40: | Line 40: | ||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
+ | namespace=CodeExample | ||
category=JObservable | category=JObservable | ||
category=CodeExample | category=CodeExample |
Revision as of 21:17, 4 July 2013
The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
[Edit Descripton] Template:Description:JObservable
Defined in[edit]
libraries/joomla/base/observable.php
Methods[edit]
Method name | Description |
---|---|
__construct | Constructor |
getState | Get the state of the JObservable object |
notify | Update each attached observer object and return an array of their return values |
attach | Attach an observer object |
detach | Detach an observer object |
Importing[edit]
jimport( 'joomla.base.observable' );
[Edit See Also] Template:SeeAlso:JObservable
Examples[edit]
<CodeExamplesForm />
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 provided by Batch1211.