Objectifying Drupal: What do you want to know?

Submitted by Larry on 7 February 2009 - 3:14pm

So we're a month away from DrupalCon DC 2009, and although the official schedule has not been published it seems likely from the preliminary schedule that my Objectifying Drupal session will be accepted. The basic idea is to help Drupal's mainly procedural army of developers get up to speed on object-oriented development, which has been gaining popularity in contrib (most notably the Views module) and will be in many parts of Drupal 7.

Of course, given how large an army of developers we have there is no one level of existing expertise I can target. There are entire multi-course college programs on OOP design, and I have an hour. :-) So, how about some preliminary feedback? What do you want to see in a one hour session on object-oriented code in Drupal?

I don't really want to waste my time (or yours) talking about rudimentary syntax if everyone already knows it, but I also don't want to waste your time (or mine) talking about complex object interaction patterns if what the audience really needs is to understand the syntax. So let me know what your skill level is coming in and what you are hoping to get out of a one hour crash course on Drupal OOP and I'll try my best to accommodate the audience.

Please only respond if you are actually planning to attend DC DC and are planning to attend this session. There's no sense in targeting my session at people who read my blog but won't be at the session. :-)

General possibilities include:

  • Classes, Interfaces, references: What are they? (Very beginner)
  • Inheritance (beginner)
  • Simple OOP patterns (beginner to intermediate)
  • More advanced OOP patterns (intermediate to advanced)
  • Exploration of where we could properly leverage OOP in Drupal but aren't yet (intermediate to advanced)
  • Where are we using OOP now (Database layer, Views, hopefully Handlers)

Anything in particular you want to cover?

chx (not verified)

7 February 2009 - 3:18pm

While basic OOP is really basic and easy to get these patterns are what make OOP so confusing and impossible to follow at least to me. So education would be welcome.

sqrt(M_PI) (not verified)

7 February 2009 - 4:34pm

Right now Drupal is close to be the first real AOP framework. AOP is much more flexible than the OOP paradigm. All we need is more hooks as "pointcuts".

Tom Friedhof (not verified)

8 February 2009 - 1:56am

I also would like to see the OOP patterns in Drupal. Learning OOP syntax is very simple, but understanding design patterns, for me at least, is much more complex. Discussing the patterns mentioned here, such as singleton, decorator, observer, bridge, and chain of responsibility, and how Drupal already uses these patterns in much more depth is valuable to me. It also would be nice to see how these patterns would look in Drupal using OOP syntax.

Thanks for the session Larry!

+1 on patterns, along with chx and Tom.

The comment on AOP is interesting, but Aspect oriented programming is achieved when in the code you can concentrate on business objects and can simply inject "handler points": we have callback functions (hooks) but we don't have the first part, OOP, yet. That's the point.

What I think would make your session awesome is if you could find an example of code debt in Drupal. An example where there is increasing complexity and it is very difficult, if not impossible, to refactor without using OOP.

I think that would go a long way towards enhancing Drupal community OOP outreach.

Victor Kane

I have seen how excessive use of objects can make PHP performance really bad. I think basic OOP knowledge (things you listed) is not enough when doing real-world PHP projects. One must also consider how to keep performance at the same level as with procedural design.

That is why I would not 'push' OOP to Drupal developers unless also prepared to provide insight on how to maintain performance.

  • Best practices of combining traditional procedural Drupal patterns with OOP, so that it still remains "the Drupal way".
  • Public member variables (structs enhanced with methods) vs. proper encapsulation (using "private" + getter/setter methods wherever possible).
  • Naming: Views-style lowercase+underscores names vs. PHP-style camel-casing for classes, methods and variables. When to use "get" as method prefix. (E.g. Qt uses prop()/setProp() instead of getProp()/setProp(), and really, isn't almost everything a getter method?)
  • Well-known Drupal code examples and when/how to do them in OOP rather then procedurally.

Patterns are cool of course, but I've already had my share of those in various OOP courses - I'm more interested in how to fit traditional OOP approaches into Drupal.

I'm thinking it would be useful to leverage developers existing knowledge of the Drupal codebase and find examples of OOP like patterns in Drupal.

For example Drupal hooks are kind of Observer/Listeners. module_invoke/module_invoke_all are kind of event dispatchers. (Those are a couple off the top of my head, but I'm sure there are plenty more - 'kind of' OO stuff in Drupal).

For each example you can talk about how its similar to OOP - and then show what it would look like if it were OO.

Another thought might be to talk about what an encapsulated and/or polymorphic node object might look like.

Like you said, its only an hour and you could spend a year architecting an object oriented DrOOple and months discussing design decisions and why one pattern was chosen over another do do things. Its a tough talk - but from reading your blog I'm sure you'll do a great job. I won't be able to get out to Drupalcon, but I look forward to watching/listening to the talk afterwards.