List Info

Thread: PEAR and interfaces




PEAR and interfaces
user name
2007-01-04 20:57:54
Hey all, sorry if this is repeatitive, and if it is please
point me to
the good documentation but I was wondering if it was ever
discussed
before. The use of interface and it's structure in pear.

Currently what I have done is something like this (package:
Path_MainPackage)

Path_MainPackage:

Interface:
--------------------
interface Path_MainPackage_Interface { }
--------------------


MainPackage class:
-----------------------
require_once
'Path/MainPackage/interface/MainPackageInterface.php';
class Path_MainPackage implements Path_MainPackage_Interface
{ }
-----------------------

Let me know if this is the good structure used for PEAR or
what shoudl
be used if it is not.

Thanks.



-- 
David Coallier,
Founder & Software Architect,
Agora Production (http://agoraproduction.com
)
51.42.06.70.18

-- 
PEAR Development Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

PEAR and interfaces
user name
2007-01-04 23:49:10
David Coallier wrote:
> Hey all, sorry if this is repeatitive, and if it is
please point me to
> the good documentation but I was wondering if it was
ever discussed
> before. The use of interface and it's structure in
pear.
> 
> Currently what I have done is something like this
(package:
> Path_MainPackage)
> 
> Path_MainPackage:
> 
> Interface:
> --------------------
> interface Path_MainPackage_Interface { }
> --------------------
> 
> 
> MainPackage class:
> -----------------------
> require_once
'Path/MainPackage/interface/MainPackageInterface.php';
> class Path_MainPackage implements
Path_MainPackage_Interface { }
> -----------------------
> 
> Let me know if this is the good structure used for PEAR
or what shoudl
> be used if it is not.

Hi,

There has been a great deal of debate on how best to do
this.  I think
that it may be better to require an I prefix.  Why? 
"Interface" can
mean more than just the language construct (think of user
interface,
etc.).  This means there is actually some unintended
ambiguity here.  It
is a recognized practice in other languages to simply
prepend I, so that
we get:

Path/MainPackage/IWhatItDoes.php

as in

PEAR2/IRegistry.php (PEAR2_IRegistry interface)

or

PhpDocumentor2/Converter/IOutput.php
(PhpDocumentor2_Converter_IOutput
interface)

Both of the examples are hypothetical, btw.

I was not in favor of this until I started implementing a
few
interfaces, and I have become convinced after using them
that this is
far clearer for code organization.

Any discussion is welcome, of course.

Greg

-- 
PEAR Development Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

PEAR and interfaces
user name
2007-01-05 00:12:21
On 1/4/07, Gregory Beaver <gregchiaraquartet.net>
wrote:
> David Coallier wrote:
> > Hey all, sorry if this is repeatitive, and if it
is please point me to
> > the good documentation but I was wondering if it
was ever discussed
> > before. The use of interface and it's structure in
pear.
> >
> > Currently what I have done is something like this
(package:
> > Path_MainPackage)
> >
> > Path_MainPackage:
> >
> > Interface:
> > --------------------
> > interface Path_MainPackage_Interface { }
> > --------------------
> >
> >
> > MainPackage class:
> > -----------------------
> > require_once
'Path/MainPackage/interface/MainPackageInterface.php';
> > class Path_MainPackage implements
Path_MainPackage_Interface { }
> > -----------------------
> >
> > Let me know if this is the good structure used for
PEAR or what shoudl
> > be used if it is not.
>
> Hi,
>
> There has been a great deal of debate on how best to do
this.  I think
> that it may be better to require an I prefix.  Why? 
"Interface" can
> mean more than just the language construct (think of
user interface,
> etc.).  This means there is actually some unintended
ambiguity here.  It
> is a recognized practice in other languages to simply
prepend I, so that
> we get:
>
> Path/MainPackage/IWhatItDoes.php

Ok well if i'm not mistaking that's what I just did, but I
have put
the interface in an interface directory.

As such as this

Path/MainPackage/interfaces/MainPackageInterface.php

so MainPackage is only using the interface from the
package's
directory and at least we know that what is in the folder
interfaces
is an interface related to the package only.

Although what I could see is something along the lines of a
general
directory for all the interfaces in pear. A centralized
interfaces
directory maybe.

In the package.xml file we could mention something like
<file role="interface" ..../>

and it would go to the interfaces folder thus calling it
would
automatically be like

<?php
require_once 'interfaces/NewPackageInterface.php';
class New_Package implements New_Package_Interface { }
?>

Of course there could be problems as such as file
replicated, etc
(namespace problems) and myabe that implementing a new
standard as
such as all interfaces must be preceded by a prefix could be
a
solution but again, this is going to be a rowdy discussion
as some
people like the prefixes and some others dont.
>
> as in
>
> PEAR2/IRegistry.php (PEAR2_IRegistry interface)
>
> or
>
> PhpDocumentor2/Converter/IOutput.php
(PhpDocumentor2_Converter_IOutput
> interface)
>
> Both of the examples are hypothetical, btw.
>
> I was not in favor of this until I started implementing
a few
> interfaces, and I have become convinced after using
them that this is
> far clearer for code organization.
>
> Any discussion is welcome, of course.
>
> Greg
>


-- 
David Coallier,
Founder & Software Architect,
Agora Production (http://agoraproduction.com
)
51.42.06.70.18

-- 
PEAR Development Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

PEAR and interfaces
user name
2007-01-05 10:09:08
David Coallier wrote:
> On 1/4/07, Gregory Beaver <gregchiaraquartet.net> wrote:
>> David Coallier wrote:
>> > Hey all, sorry if this is repeatitive, and if
it is please point me to
>> > the good documentation but I was wondering if
it was ever discussed
>> > before. The use of interface and it's
structure in pear.
>> >
>> > MainPackage class:
>> > -----------------------
>> > require_once
'Path/MainPackage/interface/MainPackageInterface.php';
>> > class Path_MainPackage implements
Path_MainPackage_Interface { }
>> > -----------------------
>> >
>> > Let me know if this is the good structure used
for PEAR or what shoudl
>> > be used if it is not.

We should use a clear mapping of class/interface names to
file names as
it makes any (auto)load implementation easier to code and
faster to run.


>> Hi,
>>
>> There has been a great deal of debate on how best
to do this.  I think
>> that it may be better to require an I prefix.  Why?
 "Interface" can
>> mean more than just the language construct (think
of user interface,
>> etc.).  This means there is actually some
unintended ambiguity here.  It
>> is a recognized practice in other languages to
simply prepend I, so that
>> we get:
>>
>> Path/MainPackage/IWhatItDoes.php

In my opinion language constructs should have precedence
over user
defined stuff. This plain 'I' is more confusing: could also
be 'Input',
'Internet' or 'iPod'... and for me it only has the smell of
lazy coders
  I
would prefer using Interface as common postfix separated by
'_'
as it is already used with exception classes, e.g.

PEAR2_Registry_Interface
PEAR2/Registry/Interface.php

If you need to implement an other sort of interface you
could use
another naming schema, e.g.

PEAR2_RegistryInterface
PEAR2/RegistryInterface.php

or you add information about what interface it is:

PEAR2_Registry_Interface_REST
PEAR2/Registry/Interface/REST.php

I don't agree that there are so many interfaces.


> Although what I could see is something along the lines
of a general
> directory for all the interfaces in pear. A centralized
interfaces
> directory maybe.
> 
> In the package.xml file we could mention something like
> <file role="interface" ..../>
> 
> and it would go to the interfaces folder thus calling
it would
> automatically be like
> 
> <?php
> require_once 'interfaces/NewPackageInterface.php';
> class New_Package implements New_Package_Interface { }
> ?>

Although it seems to be a nice idea I see many problems with
such a
concept. For me it's enough to separate packages into 'lib'
and 'data'.
Code should stay in the package directories - otherwise it
would add a
further "level of confusion"...

Regards,
Matthias



-- 
PEAR Development Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )