-
Get a monthly update on best practices for delivering successful software.

Tiling a Polygon
One of the most challenging problems I came across working on a .NET PDF Annotator and Editor application was to tile a 2-D polygon and also accurately determine the number of tiles that fill the surface of the polygon. The tiling part was not as much of a challenge as the counting part. The tiled polygon was to be rendered on a PDF document since the application in question is a PDF Annotating and Editing tool. We looked for anything the third party .NET PDF rendering/manipulation API that was used could provide for the tile rendering but there was nothing unfortunately.
Continue reading »
Topics: .NET, C#, Drawing, GDI+, Window Forms Development

Design patterns. I think they are the one of the most intriguing areas of object oriented application design and development. There are so many out there that can puzzle you each and every time you try to take a crack at them (I can name a few of them that I still can't figure how they are to be used or implemented). But a thing that most programmers would agree is if used wisely and appropriately, these design patterns can provide really powerful benefits that can enhance one's programming experience and also the software that is being built. There are several patterns I have used/implemented in my projects that I think are awesome. I ll touch upon how I used some of them and why every Object oriented programmer needs to master them.
Topics: .NET, Gang of Four, OOP
My post today comes after watching the code coverage hover just over 70%, constantly asking myself is it possible to get

100% coverage and a discuss with a few internal colleagues on the subject. Interesting to know is if I exclude the views from code coverage, I hit a high of just over 90%. So, is not testing your UI the end of the world? Not at all, as long as you use good development practices and aim to make your UI as slim as possible, without any business processing, branching or conditional type logic.
I've been very pleased with using the PureMVC framework on my current project, and haven't running into any Ah! Ha! I gotcha scenarios yet and frankly can't envision any as we continue to add new features to this application. In fact using PureMVC has helped me think more about testability of our code and its single messaging bus has been just what the doctor ordered in terms of eliminating Publishing/Subscribing to events between the various components of the system, namely Mediators, Proxies and Commands. But with great power comes great responsibility.
One could easily access the Singleton Facade of the PureMVC framework directly from your view and send a system wide message to any component interested in that message. The problem here is testability of the UI event required to trigger that system notification.
For instance in the code snippet below you would have to create an instance of the UpgradeView and simulate a click of the download button in order to test sending this notification.
Continue reading »
Topics: .NET, Pure MVC, PureMVC, user interface
PureMVC is open source framework that allows creation of application using Model, View and Controller pattern, and was original designed for Flex, Air and Flash application. It has since been port to various languages include the .NET C# language. So when I first heard about it, several months ago, I was working on a pretty large WinForm application design around the MVP - Model, View and Presenter pattern.
Our presenters were responsible for handling the user interaction coming from the views by subscribing to events published by the views, and coordinating these actions with changes needs from the models such that these changes are then reflected back in the views themselves.
Although this approached work, it requires a lot of wiring and unwiring of events from the various presenters to views, presenters to model, and presenters to presenters. So the code quickly begins to look like the following:
public class presenter1
{
public event EventHandler<EventArgs> SomethingHappened;
public presenter1()
{
_model = new Model();
_model.StateChanged += OnModelChange;
_model.DocumentSaved += OnModelSaved;
_view = new View();
_view.OnMouseDown += OnMouseDown;
_view.OnMouseUp += OnMouseUp;
_view.OnMouseMove += OnMouseMove;
_view.OnMouseEnter += OnMouseEnter;
}
…
…
As you can see, for every user interaction on the view or model change a particular presenter is interested in, you must subscribe to an event, and if other presenters are interested in particular actions from views they are not responsible for, well, I’m sure you can get the picture. So act II, introduction of PureMVC framework for WinForms.
So exploring the capabilities of PureMVC framework, uncovered a simplification of our code. At its core, it consists of four singleton objects Model, View, Controller and Façade. The Model, View and Controller contain literal string references to Proxies which are data model, Mediators which provide and manage the user interface, and Commands which interact with the Proxies and Mediators or other commands.
But the simplification revolves around the Façade which is responsible to provide messaging throughout the core framework using an Observer notification scheme. So now our code quickly begins to look like the following:
public class presenter1 : Mediator
{
public presenter1()
{
}
public override void ListNotificationOfInterest()
{
return new List<string> { Nofication.ViewMouseClick, Notification.ModelChange,};
}
public override void HandleNofication(INofication notification)
{
switch(nofication.Name)
{
case Notification.ViewMouseClick:
Dosomething();
break;
}
}
…
…
public class presenter2 : Mediator
{
public presenter2()
{
}
public override void ListNotificationOfInterest()
{
return new List<string> { Nofication.ViewMouseClick,};
}
public override void HandleNofication(INofication notification)
{
switch(nofication.Name)
{
case Notification.ViewMouseClick:
DoSomethingFun();
break;
}
}
…
…
public partial class view1 : Page
{
…
…
protected void view_mouseclicked(object sender, MouseEventArgs e)
{
Façade.NotifyObserver(new PureMVC.Pattern.Notification(Notification.Name));
}
…
…
Both presenter1 and presenter2 state they are interested in Notication.MouseClick event, and view1 uses the Façade to notify both presenters that the user has clicked the mouse button. No need to publish and subscribe to any events outside what’s naturally needed in the view.
The only thing I dislike is the name references, but as long as we are using constants you should be fine.
Related Services: .Net Application Development, Custom Software Development
I've begun my foray into the world of LINQ, and in my investigation I've seen a lot of work based on the LINQ to SQL "design surface" available in Visual Studio 2008. It's a neat tool. I point it to my database, drag some tables over, and it infers my domain structure and relationships from the databases fields and keys. That's all well and good for a simple domain model that is directly related to the database schema. I could see using this for a quick prototype, or a really small application. I see three files created by the designer:
MyClasses.dbml - This looks like any ORM frameworks mapping file. It associates classes with tables, maps fields to object properties, and defines relationships.
<table border="0"></table>
MyClasses.dbml.layout - This looks to be specific to the layout of the design surface and appears to serve no purpose outside of this design.
MyClasses.designer.cs - This is the beast that I'm looking to replace. It contains the class definitions and attribute based mappings to bring my database schema into my application, and ready it for use by LINQ.
So this leaves me with a couple questions. One, why are attributes used to specify mappings? Can this be done strictly via XML? More importantly two, can I use my own domain model, and if so how do I map it to the database?
My goal would be to design a layered system, separating the underlying data store from the repositories required to push and pull my domain objects from these data stores. This would allow in memory implementations of the data store, and would make unit testing (and developing) a whole lot easier. I will be digging into this in the coming days and will report back soon. Stay tuned!
Didier Girard, the peripatetic publisher of onGWT, read my post yesterday and pointed me toward XSTM, the open source OO distributed object cache. It has Java, .NET and GWT implementations that can interoperate.

I can now cross Microformats off my list of "technologies whose value I recognize even though I've never had the chance to use them in real life." Last week I created three hcards for the new Pathfinder website, one each for our Chicago headquarters, our New York office, and our head of sales. Now, if you've got a browser plug-in that can parse microformats, you can import our contact information directly into Outlook, Apple's Address Book or your PIM of choice.
Microformats, for those who don't immerse themselves in grassroots front-end technologies, are at the core of what's become known as the "semantic web." The basic idea is that by adopting a set of standardized markup patterns, we can create websites that are more easily parsable by both humans and machines. More from the "About microformats" page:
Designed for humans first and machines second, microformats are a set of simple, open data formats built upon existing and widely adopted standards. Instead of throwing away what works today, microformats intend to solve simpler problems first by adapting to current behaviors and usage patterns (e.g. XHTML, blogging).
The most popular and best-known microformat is the hcard, an HTML implementation of the standard vCard format used to store and exchange address and personal information in a wide variety of software applications. If vCards are basically electronic business cards that can be imported to or exported from your contacts manager, then hcards provide the same functionality in the browser.
Topics: .NET, Firefox, Firefox Extensions, Microformats, Radiant CMS, Semantic web

Back when .NET didn't have an Ajax pot to piss in, I voraciously read Michael Schwarz's blog and followed his Ajax.NET framework. He eventually released a companion "Pro" version. Now, several Microsoft MVP awards later, he is packing it in. I, for one, will miss the competition in the .NET world. That leaves two major alternatives that I'm aware of:
Since the concepts around how Ajax apps should be built are still in flux, it would be nice to have a few alternatives in the .NET world (especially ones that don't produce the XHR salad that ASP.NET Ajax does).
Technorati Tags: ajax, .net, ajaxpro.net, gaia widgets, anthem.net
Topics: .NET, Ajax Frameworks, ASP.NET, C#, Microsoft