Perfect match: Composite and Visitor Pattern


In one of my earliest post, I talked about the importantance of understanding principles of good programming, and the useful-ness of Design Patterns… in this post I intend to share some implementation of some of these patterns. Patterns are something I use from time to time on projects, and something that I’m continuously learning from reading and from others, and still enjoying it very much. Let’s proceed then…

Design Patterns can be categorized into creational, structural and behavioral. I find two patterns that work pretty well together being the Composite Pattern (structural) and the Visitor Pattern (behavior). Composite Pattern is a structural pattern that helps one create tree-like hierarchial structures whereas the Visitor Pattern is a behavioral pattern that allows a visitor object to “visit” each element in a structural hierarchy to perform some operation/behavior on that element. Read the rest of this entry »

C# 3.0 Higher Order Functions


I’ve been reading a lot about F# and functional programming, and it has indeed been pretty head-turning but it’s really powerful if you know how to use it. Type Inference in F# compiler is spectacular compared to the C# one, but I shall not digress. This post is about showing off the functional aspects of C# 3.0, namely Higher Order Functions. In short, higher order functions are functions that can take in one or more functions as input parameters, as well as return a function as an output. In C# 3.0, delegates have evolved a lot and with the introduction of the System.LINQ namespace, plus a lot of functional features have been incorporated into the language, and we’ll see how to make full use of them.

In the System.LINQ namespace, you will find a large bunch of Extension Methods for IEnumerable<T> class. Most of them are higher order functions, meaning that they take in a delegate (or pointer to a function) as an input parameter. Some of these delegate types taken as inputs are Func<T, TResult>, Action<T> and Predicate<T>. What this means is that you can pass in an Anonymous Function (Lambda Expressions and Anonymous Methods) to enable different kind of behaviors. If you’re familiar with the Strategy Pattern, programmers use this pattern in order to “plug in” different behaviors flexibly by writing a family of algorithms encapsulated within derived strategy classes. With higher order functions, I’m inclined to believe that we now have something more straightforward and powerful at our disposal.

Read the rest of this entry »

Moving to a functional state of mind with F#


In my previous post, I talked about my uneventful journey of learning a functional language and how it was revived again by discovering this great book called Functional Programming for the real world. What’s great about this book is that the authors prepare you mentally for the transition to a functional state of mind. If you are not interested in functional programming, understanding the key aspects of it is still beneficial because it opens up a different approach to solving problems, which is never a bad thing. For example, functional programmers aim to write elegant and succinct code, as well as aiming to be natural to read by making use of it’s declarative nature. Once you learn this skill, you can apply this even to static language, as we will soon see.

Read the rest of this entry »

Guide to SketchFlow in Expression Blend 3 RC


Expression Blend 3 with SketchFlow RC is finally released today, and I could not resist having a play with it. In this post, I’m going to demonstrate building a very simple prototype using SketchFlow. First you will need to download and install it. Once that’s done, open Expression Blend 3, and create a new WPF SketchFlow solution. (Or Silverlight if you wish)

Read the rest of this entry »

Expression Blend 3 + SketchFlow (RC) Released


Previously I talked about a great UI Design tool called SketchFlow, but was not available yet at the time of writing. Not anymore…

Download SketchFlow with Expression Blend 3 (RC) here. Have a play with it….:)

Is there a functional programmer inside you?


I only just realized I have had a crush on Functional Programming for ages. When I first learned and used Generics and Anonymous Methods in .NET 2.0, I instantly fell in love. Next came C# 3.0, LINQ and XAML, and I was instantly drawn to it’s declarative nature and style. Having done programming for a relatively short time, I delved mostly in Imperative Programming in statically typed languages like C#, VB.NET and C++. C# 3.0 had a facelift by getting some aspects of functional programming (like lambda expressions) and that made it more powerful, fun and simpler to write/understand. Eventually I decided to venture into the world of Functional Programming, namely F#.

Read the rest of this entry »

WPF: Window Dock Behavior


**updated this post for Blend 3 RC release

Have you ever used WinSplit Revolution? It’s a utility that helps you organize your windows into regions to assist with organizing your screen real estate. I find this to be a very useful tool, especially when I use two monitors while doing development, being able to organize my windows neatly makes a huge difference. One cool feature is called Drag’n’Go. When you drag your window outside your screen boundary, a semi-transparent rectangle (I’d like to call it an overlay) appears to cue you on the location of where the window will be docked. I really like this feature, and wondered how difficult it would be to incorporate this into a Behavior for a Window class in WPF to exhibit the same kind of functionality. Here’s my result.

DockWindow

Read the rest of this entry »

Posted in WPF. Tags: . 2 Comments »