Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

OO Design: Abstract Classes
What Is An Abstract Class?
An abstract class is a base class that is not instantiated. It provides common functionality to be inherited by subclasses. Another way to think of an abstract class is like a template. An abstract class contains no code, but instead, defines what code must be defined in subclasses.
Why create a class without any code and one that cannot be instantiated? Well, there are many situations where abstract classes are quite useful. Let's take a look...
Designing With Abstract Classes
One common use for an abstract class is at the top of an object hierarchy. Perhaps you are designing an application in which you would prefer all of your objects to share a certain set of common behavior, such as toString(). Regardless of what each object models within your business domain, you can reliably call upon this expected behavior, as long as implementation has been provided. This is an excellent situation where an abstract class will provide us with a definition for common behavior.
An interface definition is another great example of using abstract classes within your application design. In languages like Java, interfaces are defined with the type interface, and contain public method signatures exclusively. If you try to put implementation into an interface in Java, you will get a compile error. PHP does not have an interface type as such. However, you can still get the same feel, by using an abstract class and keeping out any implementation. With an interface, a certain behavior is defined that any class can implement in any way it sees fit. Furthermore, these interfaces can be composed within classes to extend their functionality even further. Later on, we'll take a look at how these interfaces can be dynamically pluggable at runtime.
[ Next Page ]

[Page 1]  [Page 2]  


Comments:
ric@hotmail.comRic McElvin04/22/05 11:07
jim@hotmail.comJim Dultz04/22/05 11:06
classesnekesa04/05/05 08:57
RE: Some improvementsEd Williams04/16/03 11:40
RE: Some improvementsOrlando Roebuck03/24/03 03:12
RE: bah! whoopie frickin doo!Ryan Norris02/26/03 13:19
RE: Some improvementsCurtis Miles02/23/03 08:24
example of abstact-class applicationIlya02/20/03 00:13
RE: bah! whoopie frickin doo!Cash02/18/03 19:22
bah! whoopie frickin doo!anonymous coward02/12/03 05:00
RE: Some improvementsJonathan Griffin02/11/03 01:14
Some improvementsJurre Thiel02/09/03 14:15
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.