Man! I used to never miss an update, and I've managed to miss three recently! I've just been quite busy dealing with house stuff, and getting used to working from home, etc. I should be settling into a routine fairly soon though.
So I sat down yesterday to write about another design pattern (before I got distracted by something shiny) and I was rather disappointed by missing language constructs.
I was going to talk about the iterator pattern, but without decent use of generics, it gets rather messy. I tried making it work using Variants, but it still was tough to make it feel elegant. Especially when you can just continue using the "Foobar.Count" and "Foobar.Item" style iterator.
Then I figured, I'll write about the memento pattern. Got part-way thru that and realized it was not going to be pretty because there's no concept of shared properties or methods (like the C++ friend operator). So that would leave all the data members exposed which is just no good.
Ok fine! How about a good old-fashioned mediator pattern? Nope! But this one's for a good reason -- it's not needed in REALbasic. Because RB is event-driven and all the controls reside on the window, you don't need a mediator to sit between them and figure out interactions -- you can place the interactions local to the control's action event. So that was a pleasant surprise!
So then I was going to write about Singletons, but there's no static methods (only static local variables, new to RB 2005), so that goes out the door. Of course, this takes out any sort of factory pattern...
Bleh!
But don't worry, I still know of other patterns I can write about, so I'm going to try to churn one out today if I get the chance.
I'm hoping the weather clears up a bit since I need to waterproof block tonight. Right now the skies look pretty bad, but the radar shows nothing around me, so who knows! I plan on heading out to the site around 4pm today (leaving work early) to get a start on the outside of the block. I just need to get the outside done so that they can come backfill around it. I can deal with the inside over the weekend then. :: crosses fingers ::
If you're looking for a new game to buy, go get Battle for Middle Earth. It's an addictive RPG. Get it. Now. Then let me know and we can play together online. :-D
Well, time to go fix more bugs!
So, should I bother reading "Head First Design Patterns"? ;P How compromised is RB when it comes to the most common patterns?
Thanks,
Sparky
The more you read up on programming stuff, the better programmer you become -- even if the data is redundant. :-)
RB has a way to handle every design pattern you want to throw at it (for the most part) -- it just depends on how pure you want to be when it comes to some things. For example, to work around the lack of a Static method for the Singleton pattern, you could always use a Module to be the factory of whatever singleton class you care about. It's still possible to get it done, it's just not as elegant as I'd like it to be.
That book freaking rocks... I've been working with patterns since college and I still read that book recently, if anything it shows you EXACTLY how to present topics to readers :)
Would you be able to get this to work for a Singleton class?
Sub Constructor()
Static singleton As MyClass
If singleton Is Nil Then singleton = Self Else Self = singleton
End Sub
There's not a technical reason why that wouldn't work, but it's a skeezy (but creative!) solution IMO. Being able to assign to self seems like you could get yourself into a mess-load of trouble if you're not careful.
All we need are static methods, and the problem goes away for singletons, factories and other creational patterns. Then code would look more like this:
Sub DoTheHappyDance()
MsgBox "Happy dance!"
End Sub
End Class
And you could use it like this:
With your suggestion, you'd still have to call New in order to fire the constructor.
I wrote an RBD column that implements Singleton in REALbasic using a tweak of an example that Joe Strout discussed at RW 2004.
---
To think of RB as being "compromised" with regard to patterns misses the point of patterns.