<?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>ElbertF &#187; oop</title>
	<atom:link href="http://elbertf.com/tag/oop/feed/" rel="self" type="application/rss+xml" />
	<link>http://elbertf.com</link>
	<description>Insights and Updates from a Tech Geek</description>
	<lastBuildDate>Sun, 15 Apr 2012 21:46:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Swiftlet 3.0</title>
		<link>http://elbertf.com/2012/01/swiftlet-3-0-easy-mvc-framework/</link>
		<comments>http://elbertf.com/2012/01/swiftlet-3-0-easy-mvc-framework/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 05:38:00 +0000</pubDate>
		<dc:creator>ElbertF</dc:creator>
				<category><![CDATA[app updates]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[gpl]]></category>
		<category><![CDATA[micro framework]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[swiftlet]]></category>

		<guid isPermaLink="false">http://elbertf.com/?p=1027</guid>
		<description><![CDATA[Three years ago I released an early version of Swiftlet, a light-weight PHP framework built for speed and security. Over time however, a lot of functionality was added and started to suffer from feature creep. My original intention of creating a maintainable framework that was easy to pick up was a bit&#160;lost. Last Sunday I [...]]]></description>
			<content:encoded><![CDATA[<p>Three years ago I released an early version of <a href="http://swiftlet.org/">Swiftlet</a>, a light-weight PHP framework built for speed and security. Over time however, a lot of functionality was added and started to suffer from <a href="http://en.wikipedia.org/wiki/Feature_creep">feature creep</a>. My original intention of creating a maintainable framework that was easy to pick up was a bit&nbsp;lost.</p>
<p>Last Sunday I had a spur of inspiration and decided to start over. With a slightly different vision, a better understanding of <a href="http://en.wikipedia.org/wiki/Model_view_controller">MVC</a> and experience gained with the project I managed to finish it the same day. The result is about 150kB of code including&nbsp;documentation.</p>
<p>If you&#8217;re unfamiliar with the <a href="http://en.wikipedia.org/wiki/Model_view_controller">model-view-controller</a> approach to programming Swiftlet might be a good starting point. The code is quite simple and hopefully the documentation makes the concept&nbsp;understandable.</p>
<h4>Source&nbsp;code</h4>
<p><a href="http://swiftlet.org/">Swiftlet on&nbsp;GitHub</a></p>
<p>Swiftlet is released under the <a href="http://www.gnu.org/licenses/gpl-3.0.txt">GNU Public&nbsp;License</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/2012/01/swiftlet-3-0-easy-mvc-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Object Oriented CSS</title>
		<link>http://elbertf.com/2009/05/object-oriented-css/</link>
		<comments>http://elbertf.com/2009/05/object-oriented-css/#comments</comments>
		<pubDate>Sat, 16 May 2009 03:56:20 +0000</pubDate>
		<dc:creator>ElbertF</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[oop]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=186</guid>
		<description><![CDATA[Okay, there is no such thing as object oriented CSS. But there are advantages in OO programming that we can use in&#160;CSS. 1 2 3 4 5 6 7 p &#123; margin: 0; &#125; &#160; #content p &#123; margin: 1em 0; &#125; In this example p would be a class and #content p would be [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, there is no such thing as object oriented CSS. But there are advantages in <a href="http://en.wikipedia.org/wiki/Object-oriented">OO programming</a> that we can use in&nbsp;CSS.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">p <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#content</span> p <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1em</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>In this example <code>p</code> would be a <em>class</em> and <code>#content p</code> would be an <em>instance</em> of that class. Let&#8217;s say the margin set in <code>p</code> is a <em>method</em> and we got the basic concepts of&nbsp;OOP.</p>
<p><span id="more-186"></span></p>
<h4>Practicle&nbsp;example</h4>
<p>A single HTML element can serve different purposes on a page. A list element for example can be used as a navigational menu (styled horizontally) and as a regular list in content (styled vertically). Sometimes it&#8217;s difficult to change one without changing the&nbsp;other.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">li <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span> <span style="color: #993333;">inside</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#menu</span> li <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#content</span> li <span style="color: #00AA00;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/* We only want bullets if a list appears in content */</span>
    <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">outside</span> <span style="color: #993333;">disc</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>Here I created two <em>instances</em> of the <code>li</code> <em>object</em>. If you change either one it won&#8217;t effect the&nbsp;other.</p>
<h4>CSS&nbsp;Reset</h4>
<p>It&#8217;s useful to reset all style properties first using a CSS reset. In the above example I simply applied <code>list-style: none inside;</code> to the <code>li</code> element so you won&#8217;t see bullets (&bull;) unless you specify it. It&#8217;s easier to just reset everything at once, like&nbsp;this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1em</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inherit</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">'Trebuchet MS'</span><span style="color: #00AA00;">,</span> Verdana<span style="color: #00AA00;">,</span> Arial<span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.4em</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span> <span style="color: #993333;">inside</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inherit</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>Adding this code on top of your CSS file will give you full control over your&nbsp;code.</p>
<p>As a bonus this will probably solve a lot of your cross-browser compatibility problems. This is because every browser applies <a href="http://lists.w3.org/Archives/Public/www-style/2008Jul/att-0124/defaultstyles.htm">different default CSS</a> to&nbsp;elements.</p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/2009/05/object-oriented-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Swiftlet — light-weight PHP framework</title>
		<link>http://elbertf.com/2009/04/swiftlet-%e2%80%94-light-weight-php-framework/</link>
		<comments>http://elbertf.com/2009/04/swiftlet-%e2%80%94-light-weight-php-framework/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 03:48:55 +0000</pubDate>
		<dc:creator>ElbertF</dc:creator>
				<category><![CDATA[app updates]]></category>
		<category><![CDATA[gpl]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[swiftlet]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=132</guid>
		<description><![CDATA[I just released an early alpha version of Swiftlet, an Open Source, light-weight PHP framework released under the GPL&#160;license. It&#8217;s targeted at developers who want to built simple websites that don&#8217;t require large and complex frameworks, but do want a solid base to work from. Swiftlet provides basic security features such as user input sanitizing, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://code.google.com/p/swiftlet/logo?logo_id=1240554537" alt="Swiftlet logo" class="left"/>I just released an early alpha version of <a href="http://swiftlet.org">Swiftlet</a>, an Open Source, light-weight PHP framework released under the <a href="http://www.gnu.org/licenses/gpl.html">GPL&nbsp;license</a>.</p>
<p>It&#8217;s targeted at developers who want to built simple websites that don&#8217;t require large and complex frameworks, but do want a solid base to work from. Swiftlet provides basic security features such as user input sanitizing,  is highly extensible thanks to the deeply integrated hook system, completely Object Oriented and separates logic from design&nbsp;(MVC).</p>
<p>Even the most basic features such as connecting to a database and output buffering are implemented as plug-ins. This means they can be modified, extended and removed without hacking into the core&nbsp;code.</p>
<p>Website:&nbsp;<a href="http://swiftlet.org/">http://swiftlet.org</a></p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/2009/04/swiftlet-%e2%80%94-light-weight-php-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: How not to pollute the global scope</title>
		<link>http://elbertf.com/2009/03/php-how-not-to-pollute-the-global-scope/</link>
		<comments>http://elbertf.com/2009/03/php-how-not-to-pollute-the-global-scope/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 04:04:27 +0000</pubDate>
		<dc:creator>ElbertF</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=62</guid>
		<description><![CDATA[An emerging trend in JavaScript is to wrap entire programs in a single object to prevent conflicts with other scripts. The same can be done with PHP, something I haven&#8217;t seen done very&#160;often. If you ever want to combine frameworks you may discover that they use similar names for some variables and functions. This can [...]]]></description>
			<content:encoded><![CDATA[<p>An emerging trend in JavaScript is to wrap entire programs in a single object to prevent conflicts with other scripts. The same can be done with PHP, something I haven&#8217;t seen done very&nbsp;often.</p>
<p><span id="more-62"></span></p>
<p>If you ever want to combine frameworks you may discover that they use similar names for some variables and functions. This can lead to unexpected output and security holes. If you&#8217;re planning on writing a framework of your own, consider wrapping it in an&nbsp;object.</p>
<p>In PHP5 it&#8217;s possible to pass objects by reference which means you can send an instance of a class to another class. This way you can nest classes and access the&nbsp;parent.</p>
<p><strong>core.php:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> core
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span>
        <span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'This is a global variable.'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">const</span>
        CONST_VAR <span style="color: #339933;">=</span> <span style="color: #0000ff;">'This is a constant.'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// This function is executed when core is initialized.</span>
    <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'classes/foo.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">foo</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> foo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// All the main functions go here.</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>foo.php:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> foo
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$core</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$core</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Reference to the core object.</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">core</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$core</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> hello_world<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">core</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">var</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In this example &#8220;core&#8221; is the site&#8217;s main object containing global variables and functions. When we create an instance of class &#8220;foo&#8221;, we send a reference to the core object (&#8220;$this&#8221;) as a parameter. On a regular page the classes, variables and function can be accessed like&nbsp;this:</p>
<p><strong>page.php</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'classes/core.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$core</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> core<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$core</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">var</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// output: This is a global variable.</span>
<span style="color: #b1b100;">echo</span> core<span style="color: #339933;">::</span><span style="color: #004000;">CONST_VAR</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// output: This is a constant.</span>
&nbsp;
<span style="color: #000088;">$core</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">foo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hello_world</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// output: This is a global variable.</span></pre></div></div>

<p>This way there is only one variable in the global scope: $core. Another advantage is that all variables declared in core are global and accessible throughout the whole&nbsp;program.</p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/2009/03/php-how-not-to-pollute-the-global-scope/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

