Re: API Thoughts?

From: Date: Mon, 27 Aug 2001 14:57:50 +0000
Subject: Re: API Thoughts?
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-64408@lists.php.net to get a copy of this message
[Sterling Hughes <sterling@designmultimedia.com>] > On Sun, 26 Aug 2001, Chuck Hagenbuch wrote: > > > Quoting Sterling Hughes <sterling@designmultimedia.com>: > > > > > Jep -- I'm writing PEAR OO wrappers for every ADT that I implement > > > in a functional manner. I'm think for the OO wrappers, seperate > > > class names wouldn't be horrible, something like: > > > > > > $tree = new AVLTree; > > > > Please stick to the naming conventions, which would make this: > > > > $tree = new ADT_Tree_AVL(); > > > > ... or something similar. Also, you could easily have a factory method: > > > > $tree = ADT::factory('tree_avl'); > > > > or: > > > > $tree = ADT_Tree::factory('avl'); > > > > The above are imho pretty ugly, and this is meant as more of a language > level feature, I'm thinking of using PEAR as more of a method of > distribution than a mindset. I'd prefer to code the OO wrapper in > PHP -- it stops me from having to be aware of changes to the Zend OO > model and writing code that works with both the functional interface > and the OO interface (some form of automatic handling of this would > be a very cool/useful feature for Zend, imho). > > The current way I have it organized is as follows: > > php4/pear/ADT.php > php4/pear/ADT/LList.php > php4/pear/ADT/Stack.php > php4/pear/ADT/Queue.php > php4/pear/ADT/AVLtree.php > php4/pear/ADT/BTree.php > php4/pear/ADT/RBTree.php > php4/pear/ADT/Heap.php > php4/pear/ADT/Set.php > > then you could do something like: > > <?php > require_once('ADT/Queue.php'); > > $sounds = new Queue; > $sounds->push("Bing"); > $sounds->push("Bamm"); > $sounds->push("Booom"); > > while ($sounds->count() > 0) { > echo $sounds->shift(); > } > ?> > > Which I think works quite nicely :) PEAR's naming conventions applies to classes written in C too. :-) The way you have your files organized above, the classes should be named ADT_Queue and so on. - Stig -- Stig Sæther Bakken <ssb@alltheweb.com> Fast Search & Transfer ASA, Trondheim, Norway

« previous php.dev (#64408) next »