Archive

Posts Tagged ‘OOP’

ActionScript: Beaten like a ginger stepchild

August 10th, 2009 19 comments

Recently there has been a lot of uproar about ActionScript from some of the more nominated ActionScript developers. People like Joa Ebert, Nicolas Canasse, Andre Michelle and Peter Elst spoke off their dissatisfaction about the current state of ActionScript, that’s it’s stuck in the middle of nowhere, that Adobe isn’t open enough about their plans with the Flash platform, that ActionScript has become too OOP, etc. etc. And though all this bashing hurts, they all got a point about their complaints.

Read more…

Categories: Dev Tags: , , ,

The Confusion about 'this'

December 5th, 2008 23 comments

I often browse through code libraries written by others and can’t deny noticing that so many developers are making exaggerated use of the ‘this’ keyword in their code. Today I came across CASAlib an otherwise very neat and certainly helpful library and after roaming through some of the code base it turns out that in most classes they’ve put ‘this’ in front of every single class property.

It seems that many newcomers to ActionScript still don’t understand the use of ‘this’ and that it’s only really necessary in rare cases, for example if a method parameter has the same name like it’s relative class property or in a few scope-related situations. It’s also good to have ‘this’ at hand if a dynamic property of a class needs to be accessed (this["foo"]) but other than that please do all a favor and throw out those unnecessary ‘this’! Ban it, lock it in your basement and don’t let it out unless there’s really a need for it!

Categories: Dev Tags: , , ,

Customizing toString()

September 8th, 2008 11 comments

When writing classes for a framework I usually put a custom toString method into important classes so that debugging becomes easier. Normally they would go like something along the lines of:

override public function toString():String {
	return "[ClassName]";
}

… Sometimes adding properties to the returned String that give back information about the class, e.g.

override public function toString():String {
	return "[ImageClass, size=" + _size + "]";
}

But writing them rigid like that is a disadvantage when you decide later to refactor class names. Admittedly it’s also not a very elegant way so I got the idea to take the class name that is returned by getQualifiedClassName(). The only problem is that getQualifiedClassName not only provides the type name but also the whole package String of the class. Regular Expressions to the rescue! After twiddling around with them for a while (I’m by no means a RegExp expert) I got my toString method into the shape that I desired:

override public function toString():String {
	return "[" + getQualifiedClassName(this).match("[^:]*$")[0] + ", size=" + _size + "]";
}

This way it matches the String returned by getQualifiedClassName with the Regular Expression [^:]*$ which checks from the right end for an arbitrary text up to the first occurring colon, but without including the colon. Taking the first element of the Array returned by match() and you got what you need!

A nice way of using this is when writing abstract classes that contain the toString method and any subclass can use that toString method without the need to override it … that is of course unless you want ot add other output information.

Learn some patterns – Advanced ActionScript 3.0 with Design Patterns

November 23rd, 2006 1 comment

I’ve been reading this book by Joey Lott and Danny Patterson since yesterday and thought I’d loose a couple of words about it …
The book starts with a chapter about application design where it explains how to go through the analysis-, design- , implementation and testing phase. It introduces how to utilize Use Case- and Class Diagrams and then gives a lesson on how to use FlexUnit for unit testing. In the second chapter is a good explanation about why and how to use Interfaces (instead of Inheritance) and after that it goes into detail with teaching nine of the more common Design Patterns, namely MVC, Singleton, Factory/Template Method, Proxy, Iterator, Composite, Decorator, Command, Memento and State. In part 3 of the book you’ll find in-depth information about AS 3.0 features like Events, data IO, E4X and Regular Expressions.

Read more…

Understanding Interfaces and Polymorphism

November 18th, 2006 2 comments

I’ve been using Interfaces a couples of time now when needed but I never fully understood those down-sized Class construct wannabes. I knew they are useful when it is required to have an universal type for different objects but I haven’t fully grasped to scope why they are so useful otherwise. Also the fact that they can’t contain properties and only public method declarations confused me.

Read more…