OO and Writing Drupal Modules

Posted by Aaron on Stack Overflow See other posts from Stack Overflow or by Aaron
Published on 2010-05-18T17:06:55Z Indexed on 2010/05/18 17:10 UTC
Read the original article Hit count: 231

Filed under:
|
|
|

Preface: Yes, I've read: http://drupal.org/node/547518

I am writing 'foo' module for Drupal6, where I am organizing the code in an OO fashion.

There's a class called Foo that has a bunch of setters and accessors, and it is working quite well at abstracting some pretty nasty code and SQL.

The question is is it common practice to expose a class for other modules, or is it better to wrap things in the more typical foo_myfnname()?

For example, if I am writing the module's docs, should I tell people to do this:

$foo = new Foo();
$something = $foo->get_something();

or tell them to call:

foo_get_something();

which under the hood does:

function foo_get_something() {
  $foo = new Foo();
  return $foo->get_something();
}

© Stack Overflow or respective owner

Related posts about drupal

Related posts about module