Re: class? package?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday 10 June 2008, Shelley wrote:
> Hi all,
>
> If you are designing with OO principles, could you give an explanation of
> what is the difference classes and packages?
>
> Several principles talks about classes and packages, such as:
> The classes in a package are reused together. If you reuse one of the
> classes in a package, you reuse them all.
>
> but few explains the difference between them.
>
> When I was summarizing the OO principles, that question confused me:
> http://phparch.cn/index.php/php/43-php-advanced-programming/170-principles-
>of-object-oriented-design
>
> Thanks in advance. :)

A class is a syntactic way of grouping behavior and data together in an 
encapsulated fashion (at least that's the PHP definition).  

A formal package is a syntactic way of grouping related classes together, 
either for easier distribution, somewhat tighter coupling, or syntactic 
sugar.  For instance, you could have 5 classes that make up your "Database 
abstraction" package; they're all discrete, but all work in concert.

PHP does not have a syntactic "package" concept.  The closest thing would be 
namespaces as implemented in PHP 5.3, but that's not out yet.  Many systems 
emulate packages with verbose class naming (eg, Database_Connection, 
Database_Query, Database_Transaction, Database_Query_Select, etc.), but I 
personally find that ugly. :-)

-- 
Larry Garfield			AIM: LOLG42
larry@xxxxxxxxxxxxxxxx		ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux