RE: [PHP] Abstract Classes?

From: Date: Sun, 23 Oct 2005 10:40:32 +0000
Subject: RE: [PHP] Abstract Classes?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-224513@lists.php.net to get a copy of this message
Thanks Jasper, That makes sense. But what benefit is there is having it as an explicitly "abstract" class? Why can't it just be a "normal" class definition which you inherit from? Sorry to be so dense.... Al > -----Original Message----- > From: Jasper Bryant-Greene [mailto:jasper@album.co.nz] > Sent: 23 October 2005 09:19 > To: Alan Lord > Cc: php-general@lists.php.net > Subject: Re: [PHP] Abstract Classes? > > 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@album.co.nz > 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 > >

« previous php.general (#224513) next »