Interfaces in object-oriented languages like Java, C# and PHP are useful language constructs for ensuring that objects will respond to certain methods. However, unlike Java and C# (until recently), PHP has optional parameters. As it turns out, this feature has an interesting (and a little bit unexpected) effect on how we can implement interfaces in PHP.
Archive for April, 2010
If you’ve ever used the .NET Framework version 3.5 of later, you’ll probably have encountered extension methods. Microsoft describes extension methods as:
Extension methods enable you to “add” methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type. For client code written in C# and Visual Basic, there is no apparent difference between calling an extension method and the methods that are actually defined in a type.
In this article, I will show you how to write a base class that will allow you to add methods to any PHP class that inherits from it at runtime. You will be able to call these methods transparently, without any special syntax.
jQTouch is a pretty nifty little jQuery plugin for making websites look like native iPhone apps. Unfortunately, beyond a bunch of examples included with the distribution, there’s not a whole lot of online documentation written for jQTouch. Having started to use jQTouch for a professional project, I thought I’d help remedy this deficiency by posting what I learned along the way.
This is part 1 of a two part series.
History lesson: Anders was lured away from Borland by Microsoft with a hefty offer of a $1.5 million signing bonus, a base salary of up to $200,000, and options to buy 75,000 shares of Microsoft stock.
Looks like it was worth it, as each C# release has added many interesting and powerful features, while maintaining a fine balance between complexity and simplicity.
While working on Flash sidescroller stuff I noticed that there was no easy way (that I could find) to create multiple sprites from a single bitmap (something you’d do when doing a tile-based graphics layout).
Here’s some example usage:
var factory:SpriteFactory = new SpriteFactory("assets/sprites"); factory.loadBitmap("grass", "block-grass.png"); var grass1:Sprite = factory.newSprite("grass"); var grass2:Sprite = factory.newSprite("grass");
Since I’m toying around with the idea of sidescrollers, I did a search for “Flash sidescroller tutorial” and found this excellent 3-parter by devnote.org. Unfortunately (for me), the tutorial expects that you’re using Adobe’s Flash IDE. Thus, as a contribution to the web (and myself… mostly myself), I translated the tutorial to work with FlashDevelop. Read on to see how I did it, or just grab the source here.