Re: Abstract Classes?

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

 



On Sun, 2005-10-23 at 08:54 +0100, Alan Lord wrote:
> Hi All,
> 
> I have started reading a couple of books about PHP 5 and whilst most of
> it is comprehensible even to me :-), I fail to understand WHY there is
> such a thing as an abstract class or method?
> 
> I think I understand what it is: A class that can't itself be
> instantiated, only inherited from, or a method that describes itself
> only in terms of what properties it accepts but no implementation
> detail.
> 
> But could someone explain why I would want to use this? I'm sure it is
> very useful but I can't quite see the benefit...

Hi Alan

Here's an example from an application framework I've been working on.

It has classes to represent the different HTTP response statuses (like
301 Moved Permanently, 304 Not Modified etc.) with required and
forbidden headers for each and different characteristics (like no
request-body allowed etc).

I have an Abstract class called HTTP_Response, from which
HTTP_Response_Moved_Permanently, HTTP_Response_Not_Modified, and many
others all inherit.

The reason HTTP_Response is abstract is because there's no such thing as
an HTTP_Response on its own. It has to be a specific type of HTTP
Response, that is a 301 Moved Permanently or a 304 Not Modified.

Does that help?

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: jasper@xxxxxxxxxxx
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

-- 
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