Perhaps I'm using the wrong terminology, but is object delegation (as
opposed to inheritance) possible?, i.e. the line
$this->registration->displayStatu s;
in the example below.
E.g. if one were to call
# Instantiate a new helpdesk
$helpdesk = new helpdesk ('theUsername', 'thePassword');
# Check
$helpdesk->checkUserStatu s ();
why does this not give the result:
Registered
Or do I just need some sort of other syntax?
# Define a helpdesk application class
class helpdesk
{
# Constructor
function helpdesk ($username, $password)
{
# Instantiate a registration
$this->registration = new registration ($username, $password)
# Do more stuff in this constructor
}
# Some other function
function checkUserStatus ()
{
$this->registration->displayStatu s;
}
}
# Define a registration class which applications can use
class registration
{
# Constructor
function registration ($username, $password)
{
// Validation of username & password at doCheck
$this->registered = (doCheck);
}
# Another function
function displayStatus ()
{
echo ($this->registered ? 'Registered' : 'Not registered');
}
}
Martin
Comment