Submit your site to the major search engines for indexing: http://www.google.com/addurl/ http://search.yahoo.com/info/submit.html http://www.bing.com/docs/submit.aspx Check that your robots.txt file is correct and not preventing crawlers from getting into your site: http://www.robotstxt.org/ Use Video and Flash sparingly, and knowing it doesn’t get indexed by crawlers Promote important content to home page, and make sure there are clean […]
Monthly Archives: December 2009
JavaScript Augmentation of types
Say we want to add methods to a certain type. For example, adding a trim function to the String type: String.method(‘trim’, function ( ) { return this.replace(/^s+|s+$/g, ”); }); document.writeln(‘”‘ + ” neat “.trim( ) + ‘”‘);
Design patterns: singletons
Singleton classes basically mean there is only one object class of a certain type running at all times. That could be used to store Global variables, for example. The way to implement it on PHP: class Preferences { private $props = array(); private static $instance; private function __construct() { } // By […]
Design patterns: Composition and Inheritance (Strategy pattern)
Instead of creating child classes, you create a new tree of classes and move some of the functionality away from the main tree. You connect the trees via object creation, meaning some of the classes in one tree contrain objects with the other classes type. The advantage is that the trees are more specialized in […]
PHP __toString() method
Useful to convert objects that, when printed (say in debugging), will give you output like “Resource ID blah blah”, or error messages telling you you can’t print the object. Example: class Person { function getName() { return “Bob”; } function getAge() { return 44; } function __toString() { // Controls how this object will represent […]
PHP __clone() method
In PHP5, objects are passed by reference, and when we do assignments with the equal sign in objects, we are in fact using the same object for both variables, all pointing to the same reference: $a = new TestObject(); $b = $a; // We end up with one object, two variables pointing to it. In […]
PHP Error handling
When there are problems, always return an Exception object to the client. Exception constructor accepts two optional arguments: an error string (error description in “plain english”) and an error code. These are the Exception object’s public methods available: getMessage() – Get the message string that was passed to the constructor. getCode() – Get the code […]
PHP interfaces
Interfaces are pure class templates that define functionality. It can contain properties and methods, but no method implementation. See the example below: interface Chargeable { public function getPrice(); } So any class that implements this interface, will look something like this: class ShopProduct implements Chargeable { // … public function getPrice() { […]
Public, private and protected methods and variables.
Public: access from everywhere. Private: access is only permitted from inside the instantiated object. Protected: accessed is permitted from inside the instantiated object, or from objects that are subclasses of the current object.
OOP Best Practices and architecture
When creating classes, make a really general abstaction of the object you have in mind (usually an abstact class or interface), and then start working your way down to the specifics using inheritance, encapsulation and polymorphism. For example: to create a book object for an ecommerce site, create something like Product / Item / Books / […]