Best practice for building modules using classes I'm looking to start building my modules as classes now that lazy/auto-load are in Drupal 7, and I'd love to look at some modules (contrib or core) that are doing a great job of it.

Is there a creative way for integrating a class as hooks? Do I implement each feature as a ctools plugin?

Any passers-by should note that D7 has new files[] declarations in module .info files for auto/lazy-loading classes/interfaces: Writing .info files (Drupal 7.x).

The following is a good read to get the motivations and the constitution (as it were) from the Drupal community Drupal programming from an object-oriented perspective.
A module is not a class by Crell is what you should read first.

The biggest OOP part in Drupal 7 is the new database abstraction layer (designed by the very same Crell and others). That implements many patterns which can and should be re-used.

For example:


Define interfaces for anything that could be switched out, only work against the interface internally. Example: SelectQueryInterface
A single class represents a single "thing". For example SelectQuery is a SELECT query, DatabaseConnection is a connection to the database and so on. See http://en.wikipedia.org/wiki/Cohesion_(computer_science)
Use of inheritance to allow to overide a certain implementation. Most classes in DBTNG can have a driver specific subclass, which is automatically used and included if existing. For example SelectQuery_mysql. How that is done.
Extenders, which are an implementation of the Decorator pattern to add additional functionality to the SelectQuery Class. Extenders can have driver specific subclasses too.


Something that is still controversaly discussed is Information hiding. DBTNG implements that by making class properties protected and disallowing direct access. On the other hand, we have hook_query_alter() and they can be changed almost freely with various by reference getter methods.