[nycphp-talk] Constants interfaces
Anirudh Zala
arzala at gmail.com
Wed Sep 3 00:34:27 EDT 2008
On Wednesday 03 September 2008 06:04:16 Michael B Allen wrote:
> How do people feel about the use of Java-ist "Constants" interfaces like:
>
> interface Sql_Constants
> {
>
> const SELECT = 1;
> const FROM = 2;
> const WHERE = 3;
> const NOT = 4;
> ....
>
> }
>
> where the objective is to permit any class that needs these constants
> to access them using "self" like:
>
> require_once 'Sql/Constants.php';
>
> class Sql_Parser implements Sql_Constants
> {
>
> public function parse($sql)
> {
> ...
> if ($tokenCode === self::WHERE) {
Hello Mike
Defining interface constants, according to me, is not good design pattern even
if it is enabled later in PHP.
Reason behind this is that Interfaces are primarily designed to define types
and not to hold data. As well as when any class implements any Interface it
means it will be implementing all the Methods defined in Interface. This is
not required in case of Constants that means primary purpose of Interface
(what is defined in the Interface must be implemented) is not met.
There are certain disadvantages also as mentioned in below thread.
http://www.trap17.com/forums/constant-interface-constant-class-t59974.html
Thanks
Anirudh Zala
> ...
>
> Mike
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
More information about the talk
mailing list