By WoozyDuck on
I am new to Drupal and PHP and I have two questions related to OO programming and Drupal's API
I am trying to understand how to Object-oriented programming in Drupal.
Imaging I want to create an abstract employee module, and let other contributors ti implement their own employee-type module by extending mine.
I kind of know how to do this using only PHP with OO method; Creating an abstract class of employee, give it few functions and then I can create separate employee-type classes and implement the entire system.
Now I am wondering how to implement this in Drupal? How I can use OO methods and classes in Drupal 6.0?
I would really appreciate if someone help me on this.
Comments
I would also like to know
I would also like to know which modules have used OOP to implement them?
There is very little OO code
There is very little OO code in Drupal, but the amount of OO code is increasing (especially when you compare major versions). In general, OOP is considered a tool, not a goal. Recommended reading: http://drupal.org/node/547518.
When you write custom modules, you can use as much OOP as you like internally, but you will find yourself using procedural code (drupal hooks) to connect your module to the Drupal framework. The (excellent) Views module does this.
Regarding your situation: you could create a custom module with OO code, but if the employees are the core data for your site, i advise you yo store the employees as nodes. The node is the native container for site content in Drupal. Using nodes to store your data will save you a lot of work because many other modules (views for instance) expand on this concept.
Using OOP just for the sake
Using OOP just for the sake of it isn't the best approach.
I'd suggest building a few modules using Drupal's procedure-oriented API and then introduce OOP where it makes the most sense structurally and logically.
Thank you both
Thank you both marcvangend and Bacteria Man for your replies
You have made it very clear, I think best approach would be using hooks in Drupal and OOP when necessary as Bacteria Man has mentioned.
Many thanks again