Re: class? package?

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

 



On Wed, Jun 11, 2008 at 12:02 AM, Larry Garfield <larry@xxxxxxxxxxxxxxxx>
wrote:

> 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. :-)


furthermore, in languages such as java (and likely others) packages have
access levels which are conceptually similar to ppp in classes.  this allows
designers to limit access to certain classes in a given package (duh); it
turns out to be quite useful.  imagine you are a library author and some of
the classes you distribute, you dont intend for your clients to use, well
then, you simply mark those classes as private.

i dont believe the php namespace concept incorporates this feature, nor do i
think its really relevant, in a source based language.  however, i do find
it relevant to the discussion ;D

-nathan

[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