JavaScript Editor Ajax software     Free javascripts 



Main Page

Using this class is simple — you start by referencing the
rss_factory.inc.php
file (which contains the
class), and creating your
$rss_feed
object:
<?php
// load the URL factory library
require_once ‘include/rss_factory.inc.php’;
// create feed
$rss_feed = new RSSFactory(‘SEOEgghead.com New Products Feed’,
http://www.seoegghead.com/seo-with-php-updates.html’,
‘Exciting new products, updated daily’);
Your class is named
RSSFactory
, and the object you create is named
$rss_feed
. You create the
object using the
new
operator, and, as you can see, you provide parameters in parentheses after the
class name.
Class? Object? An OOP Primer
The term
class
comes from the lexicon of object-oriented programming (OOP). If you
do not know much about OOP, here is a very quick primer that will help you under-
stand the
RSSFactory
, as well as other examples in this book that use this language
feature.
As the name implies, OOP puts objects at the center of the programming model. The
object
is the most important concept in the world of OOP — a self-contained entity that
has state and behavior, just like a real-world object.
A class acts as a blueprint for the object, and an object represents an instance of the
class defined by its state. You may have objects of class
Car
, for example, and create as
many
Car
objects as desired — named
$myCar
,
$johnsCar
,
$davesCar
, and so on.
But
$davesCar
may be stopped while John is busy outrunning a police officer on the
freeway at 100MPH.
So you get the idea; the class defines the
functionality
provided by the objects. All objects
of type Car will have the same basic capabilities — for example, the ability to accelerate
to a new speed. However, each individual Car object may register a different speed on
its speedometer at any particular time.
The object’s state is described by its variable fields, also called “properties.” Its func-
tionality is defined by its “methods.” These methods are functions inside a class, except
that they are called through (
->
) an object and reference the functions in the context of
the state provided by its properties.
In the particular example of the RSS Factory exercise, the class is named
RSSFactory
,
and the object you create is named
$rss_feed
. When you needed to call the
addItem
method of the
$rss_feed
object, you typed
$rss_feed->addItem
to add an item to
the object. You did this twice to add two feed items. Finally, to output the feed you
called
echo $rss_feed->get()
, which displays the feed in accordance with the
items that you added to it.
158
Chapter 7: Web Feeds and Social Bookmarking
c07.qxd:c07 10:42 158


JavaScript Editor Ajax software     Free javascripts