Hi,

While writing a public static method I came across a problem. Options or
class properties are not available, because we don't have a option
object accessible in the class, so I ended up with a quite huge amount
of optional parameters for my method:

static public function copyRecursive( $source, $destination, $depth =
-1, $followSymlinks = false, $dirMode = 0775, $fileMode = 0644 )

Frederik told me, that he had the same problem some time ago, so I
thought, that it is the right time to discuss it with you...

Possible solutions
==================

public static $options 
----------------------

A public static property called $options in the class which contains
several public static methods:

> ezcBaseFile::$options->foo = 'bar';

Pro:
  - Easy to access by the user
  - Common way of setting properties

Con:
  - No access control. $option class may be (accidently) replaced by a 
    user.

Option registry
---------------

A registry of "static" option classes in ezcBase, like:

> ezcBase::options( 'ezcBaseFile' )->foo = 'bar';

Pro:
  - Full control over contained option classes.

Con:
  - Quite unintuitive.

Passing option class
--------------------

Instead of passing several single options to a public static method, we
could use some of the common simulations of named parameters, like
passing an array, struct or option class to the called method:

> static public function copyRecursive( $source, $destination, $depth =
-1, ezcBaseFileOptions $options = null )

Pro:
  - Full control.
  - No special implementation required anywhere.

Con:
  - Unintuitive.

Summary
=======

I don't really like any of the above solutions, neither do I like the
approach of passing large amounts of (optional) paramters. Can you
imagine any other nice solutions for this?

-- 
Mit freundlichen Grüßen / Med vennlig hilsen
 
Kore Nordmann (GPG: 0xDDC70BBB)
eZ Components Developer
eZ systems Headquaters

tel +49 (0) 231-9742-7750 | fax +49 (0) 231-9742-7751
[EMAIL PROTECTED] | eZ systems | ez.no

Attachment: signature.asc
Description: This is a digitally signed message part

-- 
Components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/components

Reply via email to