I have the following objects that I would like make them cooperate between themselves. The user could create each object separated from the others and at different time. The final usage is that the user links all the objects together to compose the final one.
Invoice.php
<?php
class Invoice
{
private $header;
private $xml;
public function __construct()
{
// code that initializes $this XML tree (root)
}
public function setInvoiceHeader($invoiceHeader)
{
/* code that should merge $this->xml with the one from the $invoiceHeader param
but I can't access it here because of private visibility and I would like to avoid
the public visibility */
}
public function writeXMLDocument()
{
// code that returns the XML document
}
}
?>
InvoiceHeader.php
<?php
class InvoiceHeader
{
private $xml;
public function __construct()
{
// code that initializes $this XML tree
}
public function setTransmissionData($transmissionData)
{
/* code that should merge $this->xml with the one from the $transmissionData param
but I can't access it here because of private visibility and I would like to avoid
the public visibility */
}
}
?>
TransmissionData.php
<?php
class TransmissionData
{
private $xml;
private $transmissionIdNode;
public function __construct()
{
// code that initializes $this XML tree
}
public function setTransmissionId($idCountry, $idCode)
{
// code that creates the XML node with the params
}
}
?>
I can't find a way to pass the private
$xml between the objects.
I would like to avoid using the public
visibility because I don't want that the user can access the low-level implementation.
I would like to avoid using the inheritance and protected
visibility because I think that these objects are not so much related (InvoiceHeader is not an Invoice and TransmissionData is not an InvoiceHeader); furthermore the only thing that they would have inherit is a field.. it is like a waste to my ears.
I would like to treat them more like some components, assuming it is possible.