<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jacob Wright - Flex, AIR, PHP, etc. &#187; Object Oriented Programming</title>
	<atom:link href="http://jacwright.com/blog/category/object-oriented-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://jacwright.com/blog</link>
	<description>Flex, AIR, PHP, etc.</description>
	<lastBuildDate>Fri, 30 Jul 2010 20:57:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Simple Object Pooling in Flash</title>
		<link>http://jacwright.com/blog/389/simple-object-pooling-in-flash/</link>
		<comments>http://jacwright.com/blog/389/simple-object-pooling-in-flash/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 17:04:48 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>

		<guid isPermaLink="false">http://jacwright.com/blog/?p=389</guid>
		<description><![CDATA[Been loving 360 Flex this year! Tyler and I finally finished our presentation, and so I had some time to write a post I've been meaning to. One of the issues one comes across in building performant applications in Flash is object creation and garbage collection. Object pooling helps overcome this. Object pooling is keeping [...]]]></description>
			<content:encoded><![CDATA[<p>Been loving 360 Flex this year! Tyler and I finally finished our presentation, and so I had some time to write a post I've been meaning to.</p>
<p>One of the issues one comes across in building performant applications in Flash is object creation and garbage collection. Object pooling helps overcome this. Object pooling is keeping old objects around and reusing them instead of throwing them away and always creating new fresh objects.</p>
<p>Creating objects in Flash isn't bad. It's when you create hundreds or thousands of throw-away objects very quickly that this becomes a problem.</p>
<h3>Used Pooling in Observe</h3>
<p>For my final implementation of the <code>Observe</code> class I use objects to temporarily store information about hooks and observers that allows me to sort them based on order they were added. At first I thought how unfortunate that I have to create objects to do this when one of the major reasons for creating <code>Observe</code> is to eliminate the creation of <code>Event</code> objects every time a property change happens.</p>
<p>Fortunately I have complete control over <code>Observe</code> and its implementation (unlike Flash's Event model) and I can pool these temporary objects. Setting up pooling is very simple and I'd like to demonstrate how it can be done by pretending we're building a super-fast memory efficient best-performance tween engine. We'll go with this use case, build pooling, and let the remainder of the tween engine be left to the imagination or as an exercise of the reader to finish.</p>
<h3>Tweening Ultra-Speed</h3>
<p>Our pretend tween engine is called Tweening Ultra-Speed, because that sounds super cool. Super duper cool (k, so it's late). The biggest problem with high-peformance tween engines like GreenSock's preventing them from pushing beyond their top speeds even further is object creation and garbage-collection. In order to create a new tween the API might look like this:</p>
<div class="syntax_hilite">
<div id="actionscript-6">
<div class="actionscript">Tween.<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">target</span>: mySprite, <span style="color: #0066CC;">duration</span>: <span style="color: #cc66cc;">1000</span>, x: <span style="color: #cc66cc;">10</span>, y: <span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</div>
</div>
</div>
<p></p>
<p>No big deal, right? Unless you're pushing the limits and creating thousands of these every second. The object being created between those parentheses is being allocated some memory and then garbage collected later. Memory builds up as thousands of these are called, then drops back down (with a noticeable pause in the animation) because the garbage collection cleans up the old objects.</p>
<p>How else could we do this?</p>
<p>We need to have objects that we can reuse. We might go specific and have a <code>MovementTween</code> that holds the x/y properties. We might do a size tween that holds the width/height properties. I'm going to go with generic and do a property tween for each type of property. For now, we will cover 90% + of tween use-cases with a <code>NumberTween</code> object.</p>
<div class="syntax_hilite">
<div id="actionscript-7">
<div class="actionscript"><span style="color: #0066CC;">public</span> final <span style="color: #000000; font-weight: bold;">class</span> NumberTween<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> value:<span style="color: #0066CC;">Number</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> NumberTween<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span>, value:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">name</span> = <span style="color: #0066CC;">name</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">value</span> = value;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p>I'm keeping it simple and not including other stuff we might need such as current value and delta value, easing, and stuff like that. Now we have a concrete object that would be used like so:</p>
<div class="syntax_hilite">
<div id="actionscript-8">
<div class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> tween:Tween = <span style="color: #000000; font-weight: bold;">new</span> Tween<span style="color: #66cc66;">&#40;</span>mySprite, <span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// let's say 1000 is the duration</span><br />
tween.<span style="color: #0066CC;">addProperty</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> NumberTween<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"x"</span>, <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
tween.<span style="color: #0066CC;">addProperty</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> NumberTween<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"y"</span>, <span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</div>
</div>
<p></p>
<p>Of course, this doesn't solve the problem yet, but now that we have a concrete class, we can make a pool for <code>NumberTween</code>s. My favorite way is to add a static method on the class and using a link-list. It is very fast and light, and I think very elegant.</p>
<div class="syntax_hilite">
<div id="actionscript-9">
<div class="actionscript"><span style="color: #0066CC;">public</span> final <span style="color: #000000; font-weight: bold;">class</span> NumberTween<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> value:<span style="color: #0066CC;">Number</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> next:NumberTween; <span style="color: #808080; font-style: italic;">// this is for the link-list. We can also use this outside the pool to link our tweens together in the addProperty calls.</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> pool:NumberTween;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span>, value:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:NumberTween<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> tween:NumberTween = pool;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>tween == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> tween = <span style="color: #000000; font-weight: bold;">new</span> NumberTween<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; pool = tween.<span style="color: #006600;">next</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; tween.<span style="color: #006600;">next</span> = <span style="color: #000000; font-weight: bold;">null</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; tween.<span style="color: #0066CC;">name</span> = <span style="color: #0066CC;">name</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; tween.<span style="color: #006600;">value</span> = value;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> put<span style="color: #66cc66;">&#40;</span>tween:NumberTween<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; tween.<span style="color: #006600;">next</span> = pool;<br />
&nbsp; &nbsp; &nbsp; &nbsp; pool = tween.<span style="color: #006600;">next</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p>The important things to note here are the static <code>get</code> and <code>put</code> methods. You now use <code>get</code> to retrieve a new NumberTween instance and <code>put</code> to "release" it back to the pool once you're done with it. If your pooled object points to any objects or non-mutable types (non-string/number/boolean) this could be where it gets cleaned up too (don't keep mySprite tied in memory to a pooled <code>Tween</code> object). I've also made a method called destroy that does the same thing, puts it back into the pool. Let's say we do something similar for our <code>Tween</code> class as well.</p>
<div class="syntax_hilite">
<div id="actionscript-10">
<div class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> tween:Tween = Tween.<span style="color: #0066CC;">get</span><span style="color: #66cc66;">&#40;</span>mySprite, <span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span>;<br />
tween.<span style="color: #0066CC;">addProperty</span><span style="color: #66cc66;">&#40;</span>NumberTween.<span style="color: #0066CC;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"x"</span>, <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
tween.<span style="color: #0066CC;">addProperty</span><span style="color: #66cc66;">&#40;</span>NumberTween.<span style="color: #0066CC;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"y"</span>, <span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</div>
</div>
<p></p>
<p>Once the tween has finished running it can call a <code>Tween.put()</code> on itself which might call <code>property.constructor.put()</code> on all of its properties. The great part for this particular scenario is that you can have <code>NumberTween</code>, <code>ColorTween</code>, <code>BlurFilterTween</code>, etc. for each type you want to support! Now we may be creating thousands of tweens every second but we're recycling object instances so that object creation is limited and garbage collection isn't slowing things down. What is it they say? "Reduce, reuse, recycle."</p>
<p>This is my take on object pooling. You could create a pooling framework, but it is so simple to add pooling to a class, it doesn't seem necessary for quick things. And this pooling would speed up tween engines that much more (at the expense of more lines of code to create a tween. There are trade-offs).</p>
<p>So who's going to finish my tween engine for me?</p>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/389/simple-object-pooling-in-flash/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>ooCommerce Help</title>
		<link>http://jacwright.com/blog/46/oocommerce-help/</link>
		<comments>http://jacwright.com/blog/46/oocommerce-help/#comments</comments>
		<pubDate>Thu, 27 Oct 2005 15:14:25 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.jacwright.com/blog/46/oocommerce-help/</guid>
		<description><![CDATA[We are calling for developers who would like to join in on a fun object oriented PHP 5 ecommerce project entitle ooCommerce. Please email me or leave a comment if you would like to be a developer on this project or help in any way. The project is hosted at SourceForge and currently only has [...]]]></description>
			<content:encoded><![CDATA[<p>We are calling for developers who would like to join in on a fun object oriented PHP 5 ecommerce project entitle ooCommerce.  Please <a href="http://www.jacwright.com/blog/about/#contact">email me</a> or leave a comment if you would like to be a developer on this project or help in any way.  The project is hosted at <a href="http://sourceforge.net/projects/oocommerce/">SourceForge</a> and currently only has downloads for the template system it will be using, Arras Template.  Arras Template has a website at <a href="http://www.arrastemplate.org">www.arrastemplate.org</a>.</p>
<p>We (actually just myself right now) hope for this to be a good learning experience for others and are blogging about our design decisions how we are putting it together along the way.  This way it can be more of a case study in progress for others to learn in a more of hands-on way about object oriented programming.</p>
<p>Anyone is invited to help out, whether they know object oriented programming or not.  If OOP isn't a strong point, then you can just help coding (with guidance if desired).  If it is a strong point, then you can help in the design process as well and post some blog posts too.  I can do the design, database, classes, and all, but it would be a better project with more minds at work on it.  It will also be finished sometime this century.  Thank you for your help.</p>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/46/oocommerce-help/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ooCommerce &#8211; A Deeper Look, More Decisions</title>
		<link>http://jacwright.com/blog/44/oocommerce-a-deeper-look-more-decisions/</link>
		<comments>http://jacwright.com/blog/44/oocommerce-a-deeper-look-more-decisions/#comments</comments>
		<pubDate>Fri, 07 Oct 2005 20:08:28 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.jacwright.com/blog/?p=44</guid>
		<description><![CDATA[We've broken down our system down into some general parts <a href="http://www.jacwright.com/blog/43/the-overall-picture/" title="The Overall Picture">already</a>.  Now it's time to make some decisions on more specific pieces of ooCommerce and break the system down into some main objects.]]></description>
			<content:encoded><![CDATA[<p>We've broken down our system down into some general parts <a href="http://www.jacwright.com/blog/43/the-overall-picture/" title="The Overall Picture">already</a>.  Now it's time to make some decisions on more specific pieces of ooCommerce and break the system down into some main objects.</p>
<h3>What's in our Model</h3>
<p>Well, first off, we know we need a database to store all of our store's data.  We'll put off the database schema for now.  But what we do need to decide is what database to use.  And if we want to support several databases (which we do), what should we do to abstract the databases so that we use the same API no matter which database we use.</p>
<p>There are a few object-oriented options out there.  My favorite is Creole, a PHP 5 database abstraction layer which has a nice interface.  There is also <a href="http://www.devshed.com/c/a/PHP/Database-Abstraction-With-PHP/">PEAR's DB</a> which I've actually never used and have heard good things about.  The good things about these are that they're already built and they are actively developed which means others are fixing the bugs and adding features so we don't have to.  However, they are large, and the API of Creole is more of what Java programmers are use to and not what PHP developers are use to.  We could also create our own object oriented abstraction layer.  It would be smaller and use the API we want.  Much more simple code.  What do you think we should do?</p>
<p>The rest of the model would include the following list of objects, plus maybe a few we havn't thought of yet:</p>
<ul style="float:left">
<li>Customer</li>
<li>Address Book</li>
<li>Address</li>
<li>Payment (stored)</li>
<li>CustomerGroup</li>
<li>Order</li>
<li>OrderItem</li>
<li>PaymentMethod</li>
<li>DeliveryMethod</li>
<li>Product</li>
</ul>
<ul style="float:left">
<li>ProductReview</li>
<li>ProductSpecial</li>
<li>Catalog</li>
<li>Category</li>
<li>ShoppingCart</li>
<li>Translator</li>
<li>Pages</li>
<li>Content</li>
<li>Administrator</li>
<li>Report</li>
</ul>
<p style="clear:left">There of course will need to be an object type for each method of payment and other additions like that.  But I think we've got a pretty good layout here.  We may think of other things later, especially when we want to add features.</p>
<h3>How Will We Control Our Model</h3>
<p>The controller part of our system could be pretty simple, or pretty elaborate.  It all depends on what we value the most.  If we like simple the best, we can just have a bunch of PHP pages that our use will go to, they will run the code they need to run, using the model objects, and then they will pull in a template and output the results.  The URLs for these will be the name of the files, plus any parameters passed in the URL.  These will be pretty procedural, although we could make them into classes to keep it object oriented.  Another option is to push for search engine optimization by building our system with URLs that represent the page being displayed.  If we go simple, we will have a "product.php?id=10" or "product.php?name=james_bond_movie" displaying our products.  If we choose the more complex controller we would have "products/james_bond_movie" be our URL, which ranks it higher on the search engines.  To do this we would need to use mod_rewrite with Apache and set up our scripts to handle these URLs.  But it is very do-able.  Do we want full-featured, or do we want simplicity?  The value of ooCommerce will be higher with better features to it's users.</p>
<h3>Gotta See The View</h3>
<p>There are a million and one template systems out there (I wrote the 1,000,001 template system) and most very similar.  Smarty is the most popular it seems.  And most are similar to Smarty except less features or slower.  I happen to be partial to my templating system, <a href="http://www.jacwright.com/blog/arras/" title="The BEST Tempalting System to Walk the Face of the Earth">Arras</a>, which <em>is</em> different from most.  It is also fast, and small, and fun to use, and easy for designers to do design on.  So, I would like to use Arras.</p>
<p>So, what are your thoughts?  Please give feedback on the following design decisions.  We would love to get input.</p>
<ul>
<li>What database abstraction layer should we use?</li>
<li>Any additional classes I forgot in the model?</li>
<li>Go for a simpler controller, or nicer URLs?</li>
<li>Use Arras for the template system or something else?</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/44/oocommerce-a-deeper-look-more-decisions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ooCommerce &#8211; The Overall Picture</title>
		<link>http://jacwright.com/blog/43/oocommerce-the-overall-picture/</link>
		<comments>http://jacwright.com/blog/43/oocommerce-the-overall-picture/#comments</comments>
		<pubDate>Tue, 04 Oct 2005 22:13:59 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.jacwright.com/blog/?p=43</guid>
		<description><![CDATA[So, we're going to build an ecommerce solution, an open source one.  What pieces are involved? What are the major components of the system?  Let's get this organized using a <a href="http://www.jacwright.com/blog/19/thinking-object-oriented/#top_down" title="Top Down Approach">top down approach</a>.]]></description>
			<content:encoded><![CDATA[<p>So, we're going to build ooCommerce, an ecommerce solution, an open source one.  What pieces are involved? What are the major components of the system?  Let's get this organized using a <a href="http://www.jacwright.com/blog/19/thinking-object-oriented/#top_down" title="Top Down Approach">top down approach</a>.</p>
<p>Every ecommerce system has a few major parts in common.  One is the catalog.  This is where we can browse and search for the products.  Then, we have the shopping cart.  This is where we put the products when we want to buy them.  We have our checkout, which is the process where we can purchase what is in our shopping cart.  And lastly, many systems including ours will have a customer account section, where we can view our past orders and get support.  Actually, we are fogetting a major part of the system.  The administrative section.  This can sometimes be the largest section and will help us organize the catalog, oversee orders, configure the system, and all the other administrative tasks associated with running an ecommerce store.  Here are the "main sections."</p>
<p><img src="/blog/images/basic_sections.gif" alt="Main Ecommerce Sections" /></p>
<p>We will be storing many of the store's information in a database.  So we will need a database package (when I say package, it might be one class or a group of classes, we can figure out which later).  We also want to keep the HTML and style of the site seperate from the code as much as possible so that it can change.  This is a very important piece that osCommerce has not done well in.  It can be very difficult to reskin osCommerce.  So we will have a template package.  We want to model an actual store in our code for a simpler and easier to code/understand system.  This part will be the model and will be the one to interact with the database.  Finally, we need something that takes the pages or actions of our store user, puts together the model information and the templates, and gives it back to our user.  This will be our controller.  So, we have a model, view, controller system we will be making.  It will give us greater flexability.  Here are the "MVC sections."</p>
<p><img src="/blog/images/mvc_sections.gif" alt="Model View Controller Sections" /></p>
<p>The MVC (model, view, controller) sections aren't different from the main sections described above.  Rather, they are another way of looking at our system.  We will have a customer class (from the model) used in the admin section, the shopping cart section, the order section, and the customer account section.  The main sections above indicate the sections of the website, and the MVC sections indicate the different layers of code we will use in the website.</p>
<p>Right now we haven't gotten to our classes yet.  We've just been breaking the system up into smaller pieces.  These may be organized into folders of classes or they may just be for our own reference.</p>
<p>We have successfully broken down the system one level.  We will look at breaking down the system into small parts next time.  We are on our way to a successful ecommerce solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/43/oocommerce-the-overall-picture/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tutorial? How About a Project!</title>
		<link>http://jacwright.com/blog/42/ecommerce-project/</link>
		<comments>http://jacwright.com/blog/42/ecommerce-project/#comments</comments>
		<pubDate>Fri, 30 Sep 2005 13:26:06 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.jacwright.com/blog/?p=42</guid>
		<description><![CDATA[In writing the articles on object oriented programming I have stuck with theory.  After all, it is not language specific and takes less space to say what there is to say.  However, I have been asked by serveral to provide a tutorial or include examples on object oriented code.  Well, I've decided to do almost that.]]></description>
			<content:encoded><![CDATA[<p>In writing the articles on object oriented programming I have stuck with theory.  After all, it is not language specific and takes less space to say what there is to say.  However, I have been asked by serveral to provide a tutorial or include examples on object oriented code.  Well, I've decided to do something more.  My good friend Andrew Branch has pointed out many times before that we learn better when we do things ourselves.  And so, in that spirit, we will start a new full-fledged project together.  I will write along as we develope it about how we should try to do things, so we can more fully understand object oriented principles.  And we can all write the code for it.</p>
<h3>The Project</h3>
<p>Going back to my roots, I learned to program by hacking on <a href="http://www.oscommerce.com/" title="osCommerce, Open Source Online Shop E-Commerce Solutions">osCommerce</a> code.  I wanted to make my own ecommerce site and run my own buisness.  It was then that I discovered how enjoyable programming was and stuck with that instead.  The problem with osCommerce is, however, that it is very procedural.  It has SQL queries inline with the HTML on it's pages.  It uses functions to output pixel images.  It requires a lot of hacking to modify.  It is an adequate example of what you might call "spaghetti code."</p>
<h3>ooCommerce</h3>
<p>We will be starting a new open source project that will implement all the features of osCommerce, but in a better way.  And hopefully, since this will be more extensable, we can add many new features.  We can call this project ooCommerce for object oriented ecommerce.  I have already purchased the domains oocomerce.com, .net, and .org so that we may, eventually, have our own site for it.  And I have submitted it to Sourceforge for pending approval.  The benchmark of features we will be aiming for is listed on <a href="http://www.oscommerce.com/solutions">osCommerce's site</a>.  And, because we are going full out object oriented, we will be using PHP 5.  I am sorry if you were hoping for PHP 4, but in order to teach better OOP principles, and because PHP 4 is such a hack in terms of OOP, that's what we need to use.</p>
<p>I hope ooCommerce will be, if nothing else, a great learning experience.  Instead of a little pointless tutorial on saying "hello world" in an object oriented manner, we will actually create a full-featured system as our tutorial, implementing all that we've learned previously.  We will look at planning this project out next week, so stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/42/ecommerce-project/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP Package Management and Autoloading</title>
		<link>http://jacwright.com/blog/40/php-package-management-and-autoloading/</link>
		<comments>http://jacwright.com/blog/40/php-package-management-and-autoloading/#comments</comments>
		<pubDate>Mon, 19 Sep 2005 20:32:00 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.jacwright.com/blog/?p=40</guid>
		<description><![CDATA[In PHP 5 and greater there is a magic function called <code>__autoload</code> (note: two underscores).  <code>__autoload</code> allows us to load a class on the fly so to speak.  It only gets called when a class can not be found, then it has a chance to load the class.  If the class still can not be found, you get your regular error stating so.  <code>__autoload</code> can be really useful if all of your classes happen to be in one directory, but what happens if you are managing a large project with many packages of classes?  We will look at some different options.]]></description>
			<content:encoded><![CDATA[<p>In PHP 5 and greater there is a magic function called <code>__autoload</code> (note: two underscores).  <code>__autoload</code> allows us to load a class on the fly so to speak.  It only gets called when a class can not be found, then it has a chance to load the class.  If the class still can not be found, you get your regular error stating so.  <code>__autoload</code> can be really useful if all of your classes happen to be in one directory, but what happens if you are managing a large project with many packages of classes?  We will look at some different options.</p>
<h3>Single Directory of Classes</h3>
<p>This is the simplest solution, and the best if you have a small project.  You may have situations where you would like to load the class without creating a new instance of it, so I will be creating a <code>loadClass</code> function in each example which <code>__autoload</code> will call.  That way you may load a class manually.  Here is what you might do if all of your classes are in one directory:</p>
<div class="code">
<div class="syntax_hilite">
<div id="php-11">
<div class="php"><span style="color:#000000; font-weight:bold;">function</span> __autoload<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$className</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; loadClass<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$className</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span></p>
<p><span style="color:#000000; font-weight:bold;">function</span> loadClass<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$className</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#616100;">include_once</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'classes/'</span> . <span style="color:#0000FF;">$className</span> . <span style="color:#FF0000;">'.php'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span></div>
</div>
</div>
<p>
</div>
<p>Pretty Simple.</p>
<h3>Packages of Classes</h3>
<p>Now how about package management, with many directories of classes?  A few developers have named their classes with the package names in the class name.  For example, <code>util_Parser</code> would be the Parser class in the util directory (in your base classes directory), and <code>util_html_HTMLParser</code> would be the HTML parser class in the <code>util.html</code> package.  Here is an example of how that would work:</p>
<div class="code">
<div class="syntax_hilite">
<div id="php-12">
<div class="php"><span style="color:#000000; font-weight:bold;">function</span> __autoload<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$className</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; loadClass<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$className</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span></p>
<p><span style="color:#000000; font-weight:bold;">function</span> loadClass<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$className</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#616100;">include_once</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'classes/'</span> . <a href="http://www.php.net/str_replace"><span style="color:#000066;">str_replace</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'_'</span>, <span style="color:#FF0000;">'/'</span>, <span style="color:#0000FF;">$className</span><span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">'.php'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span></div>
</div>
</div>
<p>
</div>
<p>Simple like the first method, but we get packages now.  However, we have to actually name our classes with the package names in front of it.  We start to get very long names for some of our classes.  If we extended the Parser class we might have <code>util_html_HTMLParser</code> and <code>util_xml_XMLParser</code> or perhaps even deeper packages.  We also find refactoring difficult because if a class must move to another package, we must go through all our code and rename the class everywhere we use it.</p>
<h3>Package Management Using <code>import</code></h3>
<p>There is another way, although not as simple, which allows packages as deep as you would like, and requires minimal work when refactoring.  This is the <code>import</code> way of doing things.  <code>import</code> is a function which keeps track of what classes you <em>might</em> use in a certain script/class and then uses <code>__autoload</code> to look up the location of the class.  Here's how it works.</p>
<ul>
<li>You import the class or package using the <code>import</code> function like this, <code>import('util.html.HTMLParser');</code>, at the top of your script</li>
<li><code>import</code> stores the name of the class, 'HTMLParser', and the path to the class, 'util/html/HTMLParser.php', in a global associative array called <code>imports</code></li>
<li>When the class is utilized, <code>__autoload</code> will do a lookup in the <code>imports</code> array for the class and load it in.</li>
</ul>
<p>Here is how the code looks.  It is a bit more complicated, but very nice to use for a larger system:</p>
<div class="code">
<div class="syntax_hilite">
<div id="php-13">
<div class="php"><span style="color:#000000; font-weight:bold;">function</span> __autoload<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$className</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; loadClass<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$className</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span></p>
<p><span style="color:#000000; font-weight:bold;">function</span> loadClass<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$className</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/global"><span style="color:#000066;">global</span></a> <span style="color:#0000FF;">$imports</span>;<br />
&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$imports</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF;">$className</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">include_once</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$imports</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF;">$className</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span></p>
<p><span style="color:#0000FF;">$imports</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#000000; font-weight:bold;">function</span> import<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$import</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/global"><span style="color:#000066;">global</span></a> <span style="color:#0000FF;">$imports</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// seperate import into a package and a class</span><br />
&nbsp; &nbsp; <span style="color:#0000FF;">$lastDot</span> = <a href="http://www.php.net/strrpos"><span style="color:#000066;">strrpos</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$import</span>, <span style="color:#FF0000;">'.'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#0000FF;">$class</span> = <span style="color:#0000FF;">$lastDot</span> ? <a href="http://www.php.net/substr"><span style="color:#000066;">substr</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$import</span>, <span style="color:#0000FF;">$lastDot</span> + <span style="color:#CC66CC;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#0000FF;">$import</span>;<br />
&nbsp; &nbsp; <span style="color:#0000FF;">$package</span> = <a href="http://www.php.net/substr"><span style="color:#000066;">substr</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$import</span>, <span style="color:#CC66CC;">0</span>, <span style="color:#0000FF;">$lastDot</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// if this import has already happened, return true</span><br />
&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$imports</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF;">$class</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> || <a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$imports</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF;">$package</span>.<span style="color:#FF0000;">'.*'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">true</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// create a folder path out of the package name</span><br />
&nbsp; &nbsp; <span style="color:#0000FF;">$folder</span> = <span style="color:#FF0000;">''</span> . <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$package</span> ? <a href="http://www.php.net/str_replace"><span style="color:#000066;">str_replace</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'.'</span>, <span style="color:#FF0000;">'/'</span>, <span style="color:#0000FF;">$package</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#FF0000;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#0000FF;">$file</span> = <span style="color:#FF0000;">"$folder/$class.php"</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// make sure the folder exists</span><br />
&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<a href="http://www.php.net/file_exists"><span style="color:#000066;">file_exists</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$folder</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$back</span> = <a href="http://www.php.net/debug_backtrace"><span style="color:#000066;">debug_backtrace</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <a href="http://www.php.net/trigger_error"><span style="color:#000066;">trigger_error</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"There is no such package &lt;strong&gt;'$package'&lt;/strong&gt; -- Checked folder &lt;strong&gt;'$folder'&lt;/strong&gt;&lt;br /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Imported from &lt;strong&gt;'{$back[0]['file']}'&lt;/strong&gt; on line &lt;strong&gt;'{$back[0]['line']}'&lt;/strong&gt;&lt;br /&gt;"</span>, <span style="color:#000000; font-weight:bold;">E_USER_WARNING</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">elseif</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$class</span> != <span style="color:#FF0000;">'*'</span> &amp;&amp; !<a href="http://www.php.net/file_exists"><span style="color:#000066;">file_exists</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$file</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$back</span> = <a href="http://www.php.net/debug_backtrace"><span style="color:#000066;">debug_backtrace</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <a href="http://www.php.net/trigger_error"><span style="color:#000066;">trigger_error</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"There is no such Class &lt;strong&gt;'$import'&lt;/strong&gt; -- Checked for file &lt;strong&gt;'$file'&lt;/strong&gt;&lt;br /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Imported from &lt;strong&gt;'{$back[0]['file']}'&lt;/strong&gt; on line &lt;strong&gt;'{$back[0]['line']}'&lt;/strong&gt;&lt;br /&gt;"</span>, <span style="color:#000000; font-weight:bold;">E_USER_WARNING</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$class</span> != <span style="color:#FF0000;">'*'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// add the class and it's file location to the imports array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$imports</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF;">$class</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF;">$file</span>;<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// add all the classes from this package and their file location to the imports array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// first log the fact that this whole package was alread imported</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$imports</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">"$package.*"</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#CC66CC;">1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$dir</span> = <a href="http://www.php.net/opendir"><span style="color:#000066;">opendir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$folder</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">while</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$file</span> = <a href="http://www.php.net/readdir"><span style="color:#000066;">readdir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$dir</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> !== <span style="color:#000000; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/strrpos"><span style="color:#000066;">strrpos</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$file</span>, <span style="color:#FF0000;">'.php'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$class</span> = <a href="http://www.php.net/str_replace"><span style="color:#000066;">str_replace</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'.php'</span>, <span style="color:#FF0000;">''</span>, <span style="color:#0000FF;">$file</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// put it in the import array!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$imports</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF;">$class</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">"$folder/$file"</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span></div>
</div>
</div>
<p>
</div>
<p>There you have it.  A powerful way to manage your packages and load only classes which are needed for use.  Also, a feature of this method of autoloading classes is that you can use an asterisk, *, to import all the classes in a package.  And it only loads the classes needed because of <code>__autoload</code>.</p>
<p>Finally, this is how you would use the <code>import</code> method in your scripts:</p>
<div class="code">
<div class="syntax_hilite">
<div id="php-14">
<div class="php">import<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'util.html.HTMLParser'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
import<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'template.arras.*'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</p>
<p><span style="color:#FF9933; font-style:italic;">// here would be all of your important code</span><br />
<span style="color:#FF9933; font-style:italic;">// not worrying about including files hwen you need them</span><br />
<span style="color:#FF9933; font-style:italic;">// because you've already set it up to include them</span><br />
<span style="color:#FF9933; font-style:italic;">// automatically when you use them, and only</span><br />
<span style="color:#FF9933; font-style:italic;">// _if_ you use them</span><br />
<span style="color:#0000FF;">$p</span> = <span style="color:#000000; font-weight:bold;">new</span> HTMLParser<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#0000FF;">$t</span> = <span style="color:#000000; font-weight:bold;">new</span> ArrasTemplate<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#FF9933; font-style:italic;">// etc. </span></div>
</div>
</div>
<p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/40/php-package-management-and-autoloading/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>setProperties</title>
		<link>http://jacwright.com/blog/31/setproperties/</link>
		<comments>http://jacwright.com/blog/31/setproperties/#comments</comments>
		<pubDate>Fri, 05 Aug 2005 14:51:59 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.jacwright.com/blog/?p=31</guid>
		<description><![CDATA[One of the simple and very useful pieces of code in Pherret (a PHP 5 framework) is the <code>setProperties()</code> function in the base <code>Object</code> class.  The name originally came from Java Beans and works in a similar manner.  I'm sharing it because it could be used in any code with PHP 5 <strong>or</strong> PHP 4.]]></description>
			<content:encoded><![CDATA[<p>One of the simple and very useful pieces of code in Pherret (a PHP 5 framework) is the <code>setProperties()</code> function in the base <code>Object</code> class.  The name originally came from Java Beans and works in a similar manner.  I'm sharing it because it could be used in any code with PHP 5 <strong>or</strong> PHP 4.</p>
<p>First, here is the problem being solved.  Do you ever find yourself setting and object (or array, or variables) from a HTTP post in the following manner?</p>
<div class="code">
<div class="syntax_hilite">
<div id="php-15">
<div class="php"><span style="color:#0000FF;">$user</span> = <span style="color:#000000; font-weight:bold;">new</span> User<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#0000FF;">$user</span>-&gt;<span style="color:#006600;">firstName</span> = <span style="color:#0000FF;">$_POST</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'firstName'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;<br />
<span style="color:#0000FF;">$user</span>-&gt;<span style="color:#006600;">lastName</span> = <span style="color:#0000FF;">$_POST</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'lastName'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;<br />
<span style="color:#0000FF;">$user</span>-&gt;<span style="color:#006600;">address</span> = <span style="color:#0000FF;">$_POST</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'address'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;<br />
<span style="color:#0000FF;">$user</span>-&gt;<span style="color:#006600;">city</span> = <span style="color:#0000FF;">$_POST</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'city'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;<br />
<span style="color:#0000FF;">$user</span>-&gt;<span style="color:#006600;">state</span> = <span style="color:#0000FF;">$_POST</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'state'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;<br />
<span style="color:#0000FF;">$user</span>-&gt;<span style="color:#006600;">zip</span> = <span style="color:#0000FF;">$_POST</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'zip'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;<br />
<span style="color:#0000FF;">$user</span>-&gt;<span style="color:#006600;">email</span> = <span style="color:#0000FF;">$_POST</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'email'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</p>
<p><span style="color:#FF9933; font-style:italic;">// validate the data</span></p>
<p><span style="color:#0000FF;">$user</span>-&gt;<span style="color:#006600;">saveToDatabase</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</div>
</div>
<p>
</div>
<p>Don't you think it would be easier to do this?</p>
<div class="code">
<div class="syntax_hilite">
<div id="php-16">
<div class="php"><span style="color:#0000FF;">$user</span> = <span style="color:#000000; font-weight:bold;">new</span> User<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#0000FF;">$user</span>-&gt;<span style="color:#006600;">setProperties</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</p>
<p><span style="color:#FF9933; font-style:italic;">// validate data</span></p>
<p><span style="color:#0000FF;">$user</span>-&gt;<span style="color:#006600;">saveToDatabase</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</div>
</div>
<p>
</div>
<p>This can be done by having the <code>User</code> class extend the <code>Object</code> class.  The <code>Object</code> class has a method called <code>setProperties($params = $_REQUEST, $properties = '*', $prefix = '', $force = false)</code> which by default sets all the properties that an extending object has from the <code>$_REQUEST</code>.</p>
<p>There are many other ways you can use this method.  You can set another source to populate your object from, including <code>$_GET</code>, <code>$_POST</code>, another array or even another object.  You may also limit which properties are set by passing them into the <code>$properties</code> parameter in a comma delimited list.  To set all properties you pass <code>'*'</code>.  To set only some you would pass <code>'prop1, prop2, prop3.'</code>  If you want _all_ the properties set except one or two you may add a negative sign in front of the property like <code>'*, -prop1, -prop2'</code>, <code>'*'</code> says use all, then the <code>'-prop1,-prop2'</code> would exclude those properties.  In addition you may add a <code>$prefix</code> to the properties.  This is useful if you have two objects and want to set both properties this way (ie. <code>firstName</code>, <code>shipFirstName</code>, <code>billLastName</code>).  It takes care of the camel-case for you.  And finally, there is the <code>$force</code> parameter.  The default is <code>false</code> which means that only properties currently in the object will be set from items in the <code>$params</code> array/obj.  By setting <code>$force</code> to <code>true</code> you may force all items to be set on the object.  This is useful when you have an empty object, or one that has no class definition.</p>
<p>Now, here is what you've been waiting for.  The <code>setProperties</code> method to add to any class (or even better, any parent class).</p>
<div class="code">
<div class="syntax_hilite">
<div id="php-17">
<div class="php"><span style="color:#000000; font-weight:bold;">function</span> setProperties<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$params</span> = <span style="color:#000000; font-weight:bold;">null</span>, <span style="color:#0000FF;">$properties</span> = <span style="color:#FF0000;">"*"</span>, <span style="color:#0000FF;">$prefix</span> = <span style="color:#FF0000;">""</span>, <span style="color:#0000FF;">$force</span> = <span style="color:#000000; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/is_object"><span style="color:#000066;">is_object</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$params</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$params</span> = <a href="http://www.php.net/get_object_vars"><span style="color:#000066;">get_object_vars</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$params</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">elseif</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/empty"><span style="color:#000066;">empty</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$params</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$params</span> = <span style="color:#0000FF;">$_REQUEST</span>;<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">elseif</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<a href="http://www.php.net/is_array"><span style="color:#000066;">is_array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$params</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//throw new Exception('The $params sent to setProperties is niether an object or an array (and it should be)');</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span>;<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color:#0000FF;">$props</span> = <a href="http://www.php.net/explode"><span style="color:#000066;">explode</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">","</span>, <a href="http://www.php.net/str_replace"><span style="color:#000066;">str_replace</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">" "</span>, <span style="color:#FF0000;">""</span>, <span style="color:#0000FF;">$properties</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#0000FF;">$properties</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#616100;">foreach</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$props</span> <span style="color:#616100;">as</span> <span style="color:#0000FF;">$prop</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$prop</span> == <span style="color:#FF0000;">'*'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$properties</span> = <span style="color:#0000FF;">$force</span> ? <span style="color:#0000FF;">$params</span> : <a href="http://www.php.net/get_object_vars"><span style="color:#000066;">get_object_vars</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">elseif</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$prop</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#CC66CC;">0</span><span style="color:#006600; font-weight:bold;">&#125;</span> == <span style="color:#FF0000;">'-'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/unset"><span style="color:#000066;">unset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$properties</span><span style="color:#006600; font-weight:bold;">&#91;</span><a href="http://www.php.net/substr"><span style="color:#000066;">substr</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$prop</span>, <span style="color:#CC66CC;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$properties</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF;">$prop</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#CC66CC;">1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color:#616100;">foreach</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$properties</span> <span style="color:#616100;">as</span> <span style="color:#0000FF;">$prop</span> =&gt; <span style="color:#0000FF;">$value</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$prop</span> = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$prop</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#CC66CC;">0</span><span style="color:#006600; font-weight:bold;">&#125;</span> == <span style="color:#FF0000;">'_'</span> ? <a href="http://www.php.net/substr"><span style="color:#000066;">substr</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$prop</span>, <span style="color:#CC66CC;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#0000FF;">$prop</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$param</span> = <a href="http://www.php.net/empty"><span style="color:#000066;">empty</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$prefix</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#0000FF;">$prop</span> : <span style="color:#0000FF;">$prefix</span> . <a href="http://www.php.net/ucfirst"><span style="color:#000066;">ucfirst</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$prop</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/array_key_exists"><span style="color:#000066;">array_key_exists</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$param</span>, <span style="color:#0000FF;">$params</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$setter</span> = <span style="color:#FF0000;">"set"</span> . <a href="http://www.php.net/ucfirst"><span style="color:#000066;">ucfirst</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$prop</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#0000FF;">$setter</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF;">$param</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span></p>
<p><span style="color:#000000; font-weight:bold;">function</span> getProperties<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#616100;">return</span> <a href="http://www.php.net/get_object_vars"><span style="color:#000066;">get_object_vars</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span></div>
</div>
</div>
<p>
</div>
<p>I threw in the bonus <code>getProperties()</code> function :) </p>
<p>I hope this can save at least one developer some repetative coding in their application.</p>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/31/setproperties/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Class for the DOM</title>
		<link>http://jacwright.com/blog/29/class-for-the-dom/</link>
		<comments>http://jacwright.com/blog/29/class-for-the-dom/#comments</comments>
		<pubDate>Thu, 04 Aug 2005 04:37:47 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>

		<guid isPermaLink="false">http://www.jacwright.com/blog/?p=29</guid>
		<description><![CDATA[It's alive!!  I have created a very cool, very simple, function to create new javascript objects that are (not just act upon) HTML DOM elements.  Let me explain.  Say I have a cool new tree menu I'm creating (true story), and I want others to be able to just start creating the menu items and adding them in via javascript if they need to.  The ideal way would be to just say <code>myItem = new MenuItem('Cool Item');</code> and have it return to me the actual menu item (the TR tag or LI tag) which can be inserted into the menu.]]></description>
			<content:encoded><![CDATA[<p>It's alive!!  I have created a very cool, very simple, function to create new javascript objects that are (not just act upon) HTML DOM elements. Let me explain. Say I have a cool new tree menu I'm creating (true story), and I want others to be able to just start creating the menu items and adding them in via javascript if they need to.  The ideal way would be to just say myItem = new MenuItem('Cool Item'); and have it return to me the actual menu item (the TR tag or LI tag) which can be inserted into the menu.</p>
<p>No more of this element wrapper stuff.  I don't want to code my classes to <strong>act</strong> upon a DOM element.  I want to write them as if they actually <strong>are</strong>the DOM element, just a specialized one.  This makes much more sense to me as I am working with the objects of the DOM.</p>
<p>Here is the code:</p>
<div class="code">
<div class="syntax_hilite">
<div id="javascript-18">
<div class="javascript"><span style="color: #003366; font-weight: bold;">var</span> DOMClass = <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; create: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>element<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> div = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; div.<span style="color: #006600;">innerHTML</span> = element;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> elem = div.<span style="color: #006600;">firstChild</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">delete</span> div;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> property <span style="color: #000066; font-weight: bold;">in</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elem<span style="color: #66cc66;">&#91;</span>property<span style="color: #66cc66;">&#93;</span> = <span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#91;</span>property<span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">initialize</span><span style="color: #66cc66;">&#41;</span> elem.<span style="color: #006600;">initialize</span>.<span style="color: #006600;">apply</span><span style="color: #66cc66;">&#40;</span>elem, arguments<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> elem;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span>;</div>
</div>
</div>
<p>
</div>
<p>You can just add this to your <a href="http://prototype.conio.net/" target="_blank" title="Prototype JavaScript Framework">Prototype</a> library or something.  Then start making your components.</p>
<p>The way to use this is pretty straightforward.  First, you create a new "class" like so:</p>
<div class="code">
<div class="syntax_hilite">
<div id="javascript-19">
<div class="javascript">MySentence = DOMClass.<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'&lt;p&gt;This is my &lt;strong&gt;great&lt;/strong&gt; text&lt;/p&gt;'</span><span style="color: #66cc66;">&#41;</span>;<br />
MySentence.<span style="color: #006600;">prototype</span> = <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; initialize: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i = <span style="color: #CC0000;">0</span>; i &lt;this.<span style="color: #006600;">childNodes</span>.<span style="color: #006600;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">childNodes</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">nodeName</span> == <span style="color: #3366CC;">'STRONG'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">word</span> = <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">childNodes</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>,<br />
&nbsp; &nbsp; rewrite: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>word<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">word</span>.<span style="color: #006600;">innerHTML</span> = word;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span>;</div>
</div>
</div>
<p></div>
<p>Let's walk through this step by step.  First, I create a new class called MySentence. It will be a paragraph element and it will have some text inside of it (the contents are not required). Simple enough. I can then declare my prototype for the class which will contain all the methods of my new class, including an initialize method which will be called if it exists. In the initialize method I find the STRONG tag and assign it to the property "word" for use in my other method, rewrite. That method just changes the word inside the STRONG tag. I now have a class that when created, will be a paragraph with some <strong>great</strong> text inside of it and a method to rewrite the word "great." You may even try it out and see it working in action. Here is a fun test:</p>
<div class="code">
<div class="syntax_hilite">
<div id="javascript-20">
<div class="javascript">window.<span style="color: #000066;">onload</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> s = <span style="color: #003366; font-weight: bold;">new</span> MySentence<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; document.<span style="color: #006600;">body</span>.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>s<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; s.<span style="color: #006600;">onclick</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">rewrite</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'pretty good'</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span>;</div>
</div>
</div>
<p>
</div>
<p>Putting all of the above code in a HTML page will give you some text that when clicked on, will change the wording. Pretty useful huh! Ok, so maybe this particular example isn't uber useful, but coding new objects, widgets, and components might be easier.  At least a little bit.  You may see the above <a href="/blog/DOMClass.html">example in action</a>.</p>
<p>I'll see what I can add onto this to make it better.  Perhaps something where you can access the tags inside by saying this.word = this.strong[0]; instead of having to loop through all the children.</p>
<p>This class works for both IE 6 and Firefox.  I would be very interested to know how many other browsers it worked on.</p>
<p>I have another javascript goody that my friend <a href="http://www.dexlo.com/wordpress/" target="_blank" title="Dexlo">Derek</a> and I worked on together which is pretty cool.  I'll share that soon too.</p>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/29/class-for-the-dom/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating Objects (4 of 5)</title>
		<link>http://jacwright.com/blog/22/creating-objects/</link>
		<comments>http://jacwright.com/blog/22/creating-objects/#comments</comments>
		<pubDate>Mon, 18 Jul 2005 15:49:36 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>

		<guid isPermaLink="false">http://www.jacwright.com/blog/?p=22</guid>
		<description><![CDATA[In the previous three object oriented programming articles written for <a href="http://www.jacwright.com/" title="Jac Wright, Web Development and Application Design">jacwright.com</a>, we <a href="http://www.jacwright.com/blog/18/an-introduction-to-object-oriented-programming/" title="Introduction to Object Oriented Programming">introduced</a> object oriented programming, spoke of <a href="http://www.jacwright.com/blog/19/thinking-object-oriented/" title="Thinking Object Oriented">thinking</a> about a system object oriented, and discussed the importance of <a href="http://www.jacwright.com/blog/20/planning-systems/" title="Planning Systems">planning</a>, even if only in one's head. The next two articles, Creating Objects and Reusing Objects, delve into the meatier subject of writing objects. We will be discussing how to implement the plans we've made and the systems we've conceptualized. Without these principles, object oriented programming can become a mess instead of a blessing.]]></description>
			<content:encoded><![CDATA[<p>This is the fourth of five articles on object oriented-programming.</p>
<ul>
<li><a href="http://www.jacwright.com/blog/18/an-introduction-to-object-oriented-programming/">An Introduction to Object-Oriented Programming</a></li>
<li><a href="http://www.jacwright.com/blog/19/thinking-object-oriented/">Thinking Object-Oriented</a></li>
<li><a href="http://www.jacwright.com/blog/20/planning-systems/">Planning an Application</a></li>
<li><a href="http://www.jacwright.com/blog/22/creating-objects/">Creating Objects</a></li>
<li>Making Objects Reusable</li>
</ul>
<p>In the previous three object oriented programming articles written for <a href="http://www.jacwright.com/" title="Jac Wright, Web Development and Application Design">jacwright.com</a>, we <a href="http://www.jacwright.com/blog/18/an-introduction-to-object-oriented-programming/" title="Introduction to Object Oriented Programming">introduced</a> object oriented programming, spoke of <a href="http://www.jacwright.com/blog/19/thinking-object-oriented/" title="Thinking Object Oriented">thinking</a> about a system object oriented, and discussed the importance of <a href="http://www.jacwright.com/blog/20/planning-systems/" title="Planning Systems">planning</a>, even if only in one's head. The next two articles, Creating Objects and Reusing Objects, delve into the meatier subject of writing objects. We will be discussing how to implement the plans we've made and the systems we've conceptualized. Without these principles, object oriented programming can become a mess instead of a blessing.</p>
<h3>Encapsulate, Encapsulate, Dance to the Music <a href="http://www.twin-music.com/azlyrics/t_file/songs/3dn/cel.html" title="Three Dog Night" target="_blank" style="font-size:10px">(lyrics)</a></h3>
<p>Encapsulation means keeping your business to yourself. Objects can't be bothering others with their issues. Other objects have their own stuff to worry about. When we create an object it needs to have methods for other objects to speak with it, but it should rely on others as little as possible. There are two terms we use to describe how encapsulated an object is: "<a href="http://en.wikipedia.org/wiki/Black_box" title="Black Box" target="_blank">black box</a>" and "<a href="http://en.wikipedia.org/wiki/White_box" title="White Box" target="_blank">white box</a>".</p>
<p>Black box describes an object that is completely encapsulated, closed up, secretive. We don't know anything that's going on inside of this type of object. We also can't see anything inside it. We must ask it for anything and everything we want to know about it. For example, a black box object has "getters" and "setters" to access it's properties. A getter or setter is simply a method that returns the object's properties. So instead of looking at the object's properties directly, we must request the properties through these methods.</p>
<p>White box describes an object that is not quite so into security. It doesn't care if other's know what it likes for breakfast or it's favorite color. Often we access it's properties direc</p>
<p>tly. It may also require us to know more about it in order to use,  making it not as easy to use. It may be more needy than a black box object, wanting us to find out about it. We may need to pass it's properties around to it's methods and/or call several of its methods to accomplish one task.</p>
<h4>It's Not Just Black and White</h4>
<p>Although these terms, black box and white box, help give us a way to describe objects, it's not so black and white. There are varying shades of gray in between. But black box is best, right? Well, again, things aren't so simple. Writing a black box objects means that we need to take more time to write it's getters and setters and make sure only necessary methods are publicly accessible. White box objects can be quicker to build and give us more control over the object. They also don't have to be written to be needy. Black is generally more user friendly (because we don't need to know more than we have to) and white is generally more flexible (because we have more control outside the object).</p>
<p>When is a good time to use black box, and when should we use white box then? Good question, glad I asked. If we are creating an object that we will be releasing to the world, or an object that is going to be reused over and over, or an object that we want to be used in just the right way and not any other, we would probably go with a darker shade of box. If the object in question is only going to be used once, if it will only be used by us, or if we want the object to be as flexible as possible.</p>
<h3>Extend</h3>
<p>Extending an object is having sub-objects based off of the parent. It helps us reuse code, but at the expense of greater portability. We may have a person class with child classes extending it of customer and employee. We may put the similar code in person that customer and employee both share, such as name, address, and a method to store the object. We can then put the unique code in the child classes. Employee will have payroll information and maybe a method to give a bonus. Customer will have a shopping cart and maybe an account.</p>
<p>Extending is a great way to reuse code, and it makes good sense. We are able to reuse code effectivly between related objects, and if there needs to be a change (for example, we now want to keep track of first name and last name seperatly for all people in our database) then we only need to change it in one place. We also can make the child objects fully black box so that nothing need be known about it. However, if we ever wanted to use our Employee class in another system, we would need to make sure we brought it as well as it's parent class, Person, over to the new system.</p>
<h4>Beware Family Trees</h4>
<p>There is a caution to be added here. It may sometimes become tempting to create whole family trees, reusing code from the whole system. This is generally a bad idea. Inheritance may work best when it is only a few generations. The reason for this is simple. As stated above, if we wanted to reuse an object in another system, we would have to bring the whole tree over with the object. It also can start to become confusing with so many classes dependant on others. The only time I would suggest extending more than a few generations is when creating a system such as a framework, a component set, a module or something else that would always be packaged together. Even in these situations, there may be a better way to use functionality if it makes sense, and that is object composition. </p>
<h3>Compose</h3>
<p>Object composition is another way to reuse code. Unlike extending where we inherit methods and properties from parent classes, with composition we make an object with other objects. This could be likened to the human body, one complete object made up of many other objects. The body ties everything together, helping the heart, the braing, the lungs to all work together. The customer's shopping cart in the previous example could become a seperate object that belongs to the customer. This may make more sense, to keep objects more simple. It increases organization. Of course, like anything else, to much of a good thing can be bad. We wouldn't want the customer to have a name object which contains his first name and last name. We would start to have more objects than we knew what to do with if we were breaking them down so small.</p>
<p>Composition is used very often, most any object oriented programs. Larger objects are made up of smaller pieces. It also can be more reusable. The employee object could be used without needing his payroll object and other (non-essential) objects that make him up.</p>
<h3>Object Creation</h3>
<p>Creating objects is a balancing act. Many decisions are made (often subconsiously) about how encapsulated to make an object, how to extend it, and how to compose it. The road to becoming proficient at object oriented programming may often start out with too few of these principles implemented. Then, once they are learned, it may become overused, making systems too complex. Finally, a middle ground will be found when it is remembered that the underlying purpose of object oriented programming is not to reuse but to simplify and organize.</p>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/22/creating-objects/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Very Suprised</title>
		<link>http://jacwright.com/blog/21/very-suprised/</link>
		<comments>http://jacwright.com/blog/21/very-suprised/#comments</comments>
		<pubDate>Mon, 27 Jun 2005 17:46:32 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>

		<guid isPermaLink="false">http://www.jacwright.com/blog/?p=21</guid>
		<description><![CDATA[I recently watched an email discussion comparing object-oriented programming and procedural programming in PHP.  I was very surprised to see how many people there are that don’t understand the benefits of object-oriented programming and feel procedural is usually the best tool for the job.]]></description>
			<content:encoded><![CDATA[<p>I recently watched an email discussion comparing object-oriented programming and procedural programming in PHP.  I was very surprised to see how many people there are that don’t understand the benefits of object-oriented programming and feel procedural is usually the best tool for the job.</p>
<h3>Why Object-Oriented Programming?</h3>
<p>The discussion began with a question, “why [do] folks like OOP so much in PHP?”  Few of responses attempted to answer the question but most seemed to agree that perhaps OOP is over-rated and used in too many circumstances.  I would like to answer that question for anyone interested and to explain why people like object-oriented programming.</p>
<h3>In My Beginning</h3>
<p>I began programming two years ago.  It started with my brilliant idea to start my own ecommerce company selling computers and stuff related to that.  I downloaded the latest version of osCommerce and got my store all set up.  Of course, the default installation of osCommerce is never enough (especially if you want to brand your store nicely) and so I started hacking away at the code not knowing much HTML let alone any PHP.  Soon I taught myself PHP.  In fact, I loved making MY code work in the browser so much that I changed my career path and decided to be a programmer (it was a hard decision; I didn’t want to become a geek).  I got my first job doing PHP and became an excellent procedural programmer (I learned PHP from osCommerce after all, not saying that it is excellent though, just procedural).</p>
<p>My father, a traditional C++ programmer (another reason the decision to become a programmer was hard; didn’t want to be as geeky as him; sorry Dad) who has worked for companies such as Eyering, WordPerfect, and Novell told me about object-oriented programming and how it was just better.  I assumed he knew best since he’d been around longer than I (much longer).  So I learned as much as I could about OOP and started programming that way.</p>
<p>It was difficult at first.  It was very hard for me to conceptualize how things were supposed to work as objects.  But I felt it was exciting too.  I was learning more about programming and how to be a better programmer.  It is because it was difficult for me to start thinking in terms of objects that I am writing articles about such.  The writing of classes and methods was easy.  It was doing the whole system correctly that I struggled with.  I guess what you would call OOP theory and design.</p>
<h3>At Present</h3>
<p>Since that weak start two years ago I’ve become proficient with OOP.  I’ve learned Java (not by choice, but still, not bad huh?) and done a couple of large projects with that.  Of course, PHP is still so nice to program in and I was very grateful when I was able to come back to it.  I’ve done many projects that were OOP.  I’ve gone back and worked on projects that were procedural.  I know all sides of the fence intimately.</p>
<h3>Why?</h3>
<p>Object-oriented programming is easier.  Once you know it, it becomes such a pain to work on a project that is procedural.  It is just so very much easier.  Everyone I know who knows how to program object-oriented, uses it in everything except for the smallest of applications or scripts.  If it’s a simple script, procedural all the way.  But if it’s an application of even small size, OOP just makes it easier.</p>
<p>Some say it seems there needs to be a LOT of structure for an OOP program.  Actually, it provides a lot of structure, and MAKES IT EASIER.  There are concerns that the program runs slower.  Are we seriously concerned about this?  Class definitions are not heavy.  This is not Java we’re talking about, like a whale sitting in your memory.  We probably have to measure the difference in clock cycles as opposed to milliseconds.  Besides, web applications are a little slower anyway, that’s why we use PHP, an interpreted language, in the first place.  It speeds up development and the applications are never so robust that doing it in C would be desired (except for search engines and such, but they probably don’t use C for generating the HTML pages).</p>
<p>Object-oriented programming is just procedural code organized to another level.  It makes things so much easier (yes, I keep saying that, but I think that’s why people are scared of it, because the feel it makes things MORE complicated).  The only time you wouldn’t use it if you knew it would be when writing small scripts.  I recently wrote a database transition script to move all the data from one database schema to another.  It’s like a baby who won’t walk because they can crawl just fine.  Sure, there are times when you need to get down and crawl, but you aren’t going to make that your default mode of transportation.</p>
<p>Object-oriented programming is an “oft overused methodology.”  Said by one who I’m sure has probably seen some really bad OOP code used as a hack.  There is plenty of bad OOP code out there as there is bad procedural.  Looking back for example, I would say osCommerce is bad procedural code.  The database queries are scattered throughout the pages.  Good procedural would centralize things and use functions to access them, so when there are changes you don’t have to hit every single file.  OOP is the same way.  You can make it really, really bad.  But OOP itself is still better.</p>
<p>PHP is not true OOP at heart.  Yes, true, but that does not mean that programming object-oriented in PHP will make things more difficult.  It still makes things easier.  Even in PHP 4.  PHP 5 does make things a whole lot nicer, but PHP 4 applications are still easier to make when we use objects.  I’m not saying every ounce of code should be an object or a class.  But the general application will be easier to program (for those who know both procedural and OOP) if it is done object-oriented.</p>
<h3>Conclusion</h3>
<p>There can be great procedural programs.  You don’t need OOP.  But it is the next step to becoming a greater developer and being able to write easier and more maintainable code.  It is not a marketing scheme (like Java is) with someone trying to make a profit off of it.  It is a way that helps us develop programs easier.</p>
<p>I know this article may upset many people.  I apologize if you are offended.  There is a reason why so many folks like OOP.  And it is that it makes programming easier, debugging easier, refactoring easier, upgrading easer, and expanding easier.  There are no major drawbacks to programming web-apps OOP, just benefits.  Only low-level drivers, operating systems, or search engines and like systems.  But no one in PHP will be writing anything like that.  I hope.</p>
<p>I may not have been a developer for 20 years, but I do know that just because you have, you are not necessarily a great programmer.  And I know that there are great programmers who have only been developers for a few years (I hope I can be one of them).  But I have never met anyone or talked with anyone who has programmed object-oriented for years and felt it was over-used or that procedural was generally better.  I was very supprised that people felt OOP was not a step up.</p>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/21/very-suprised/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
