Using this class is simple — you start by referencing the
file (which contains the
class), and creating your
// load the URL factory library
// create feed
$rss_feed = new RSSFactory(‘SEOEgghead.com New Products Feed’,
‘Exciting new products, updated daily’);
Your class is named
, and the object you create is named
. You create the
object using the
operator, and, as you can see, you provide parameters in parentheses after the
Class? Object? An OOP Primer
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-
, as well as other examples in this book that use this language
As the name implies, OOP puts objects at the center of the programming model. The
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
, for example, and create as
objects as desired — named
, and so on.
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
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
and the object you create is named
. When you needed to call the
method of the
object, you typed
to add an item to
the object. You did this twice to add two feed items. Finally, to output the feed you
, which displays the feed in accordance with the
items that you added to it.
Chapter 7: Web Feeds and Social Bookmarking
c07.qxd:c07 10:42 158