Templates for dynamic CMS components (event driven?)
Sorry my title is not great, this is my first real punt when going 100% in OO as I've been procedural for more years than I remember. I find it difficult to understand if what I am trying to do is possible. Depending on the thoughts of people on the next two points, I go down this route.
The CMS I am putting together is a small quote, however it focuses very heavily on different types of content. I could easily use Drupal, which I am very comfortable with, but I want to give me really good reasons to move to design templates / OO -PHP
1) I created a base content class that I want to extend to handle different types of content. The base class, for example, handles HTML content, and extensions can handle XML or PDF output. On the other hand, at some point, I might completely extend the base class for a given project. That is, if the 'content-v2' class is the extended class 'content' for this site, any calls to that class should actually call 'content-v2'. Is it possible?
If the code instantiates an object of type "content" - I really want it to instantiate one of the "content-v2" types ... I can see how to do this using inheritance, but that seems to be related to the link to class explicitly, I can't see how to bind the class that I want to use dynamically instead.
2) Secondly, the way I am building this at the moment is terrible, I am not happy with it. It feels very linear, i.e. Get session information> get content> build navigation> page theme> publish. For this, all objects are called 1-by-1, which are all very static. I would like it to be more dynamic so that I can add a later date to it (very closely related to the first question).
Is there a way that instead of my orchestra class calls all the other 1-by-1 classes and then builds everything at the end, that instead, each of the other classes can "listen" to certain events, then jump to a suitable point and do them, but ? That way, the orchestra class didn't have to know what other classes were needed and call them 1-by-1.
Sorry if I got it all worked out in my head. I am trying to structure this so that it is really flexible.
a source to share
For your question about working with Content
and Content-v2
(which are terrifying names, btw) ...
- More on encapsulation and polymorphism
- It seems to me you want a class
BaseContent
that is an abstract class that is never consumed by anything other than inheritance. - Your class
BaseContent
you need to have classesHtmlContent
,PdfContent
,MSWordContent
etc. And if you want, you can even extend them, for example withHtmlReportContent
(extendsHtmlContent
), MSWord2010Content, etc. - By doing it this way, you can declare and store variables of all BaseContent types, but when you create them, you create them as your type. When you do this, even if you have a Render () method implemented in your BaseContent class, your child classes can use the base Render () method or override it and provide their own implementation or even override it. a custom implementation and then call the base implementation to benefit from that implementation.
If you have a common implementation or behavior (for example, a class Chihuahua
and GermanShepard
would have a function Bark()
, but they would be implemented differently), then abstract that common implementation or behavior from the base of the class. You don't need to provide an implementation in your base class - why is it an abstract class and then forces its child classes to implement it ( Bark()
will be defined in your class BaseDog
, but not implemented).
Regarding the flow of your system ... For your object oriented design, consider developing
a source to share