I have two classes, the Page class and the Template class. A page has a template associated with it, so it stores an object of the Template class as one of it's properties.
Here is my issue. These calsses are used in templating a page. If I want to include the template file, I would call include $Template->view();
. However, since this object is a property of the a Page object, I have to call include $Page->template->view();
.
This sticks me in the middle of two problems.
- If I leave the
$Page->template
variable public, it could be overwritten at any point with something that isn't a Template object. - Make the
$Page->template
variable private, and I can no longer access it as I want to by calling$Page->template->method();
.
From my point of view, the only option is wrapper methods in the Page class, such as $Page->templateView();
.
I am the only one coding this, so option 1 is acceptable, as I will simply no overwrite it, but I wonder if there's a better way. If only there were properties that could be used publicly but not modified publicly.
Is there another choice for handling this type of thing?
Am I over thinking this or missing something?