Sunday, June 13, 2010
Prism is witchery
I began writing the framework for the new project with heavy guidance of Prism (RegionManager, EventAggregator, DelegateCommands and CommandBehaviors). In the end, we had some modules building a master-detail view with database-access. This was the time when other coworkers started to complain that the architecture is way too complex for such a small application as it is today. We started to discuss how to simplify it and at the end we had a draw in our opinions: some people wanted to keep everything (me included *g*) and some wanted to strip it down to remove Prism, to abolish dependency injection and the IoC container Unity. Our boss had to decide it and spoke to us: "thou shalt remove Prism but keep DI for a better TDD").
The top-3 reasons why Prism is evil for us* are:
(*) i.e. not for me
3) Using the app.config for setting up the modules is error-prone and not type-safe.
I told them that we could do it in code also but somehow I got not heared :/
2) Debugging is too hard.
When you get an exception in a view which will be inserted into a region, you got this Prism-Exception telling you that there was a problem resolving this module for that region. I learned here that you cannot expect everyone to look at inner-exceptions (admittedly mostly at level >5)...
1) Top reason why Prism is evil: it is too intransparent how the regions get filled (witchery *hooo*).
What can I say? For sure, you have to look at the good documentation at their homepage to get the hang of it. Else it's witchery, yes.
So we burned it and removed it from our solution with 10+ modules and about 10,000 loc. We needed 5 hours to remove the lightweight Prism-sections completely and substitute it with our own RegionManager-approach (which is basically the same) and with our own DelegateCommand-approach (wich is basically the same) and without the help for commanding of Prism (we now use code-behind to execute the commands). Ah yes, and we copied the EventAggregator out of the Prism-sourcecode and use it now, because our approach would be basically the same...
Everyone feels better now that the evil is being distroyed.
What was the problem? We're using a whole bunch of new technologies and paradigms in this project (WPF is new to us, as Entity framework, WCF, Prism, TestDrivenDevelopment and dependency injection). This means a lot to learn and sooner or later, your retentiveness is exhausted. This meant to sacrifice a pawn, in this case it was Prism.
Wednesday, August 5, 2009
How to build a collection of Interfaces
Here’s the problem: we have some files and some devices which operate with signals. As a signal is one of our main objects, we want to return a collection of signals when opening a file or beginning a communication with a device:

But of course, we want to handle each signal the same, so a signal from an EDF-file should be from the same class as a signal from a device. We could define a signal-class in the Main-library like this:

But this constructs a circular reference. We could create a converter for each special signal and build a collection in the main-library of all signals:

Ouch – ugly. For every signal-type we need one converter. What happens when DeviceSignal changes? Hopefully, we update the corresponding DeviceSignalConverter... Here’s my solution:

We implement all interfaces a signal could be loaded / imported from in the main-signal-class and use generics to simulate a factory. A EDF-dll could have:
public interface ISignal {
int SamplesPerRecord { get; set; }
}
public class SignalReaderwhere T : ISignal, new() {
public override ICollectionGetSignals() {
Listsignals = new List ();
var signal = new T();
signal.SamplesPerRecord = 3;
signals.Add(signal);
return signals;
}
}
The signal in the main-library implements that interface:
public class Signal : ISignal {
public int SamplesPerRecord { get; set; }
}
We can now call the SignalReader and it returns us a collection of signals we can use:
public ICollectionGetSignals() {
SignalReaderreader = new SignalReader ();
return reader.GetSignals();
}
We can implement further signal-readers just by implementing the necessary interfaces into the main-signal-class. In fact, for each reader we created from Signal inherited classes implementing the interface the reader defines. With that construct, we can work without circular references and get a collection of objects we can work with.
Wednesday, June 10, 2009
What a wonderful world
Recently I read a lot about the M-V-VM pattern and I wanted to try it out. So I started small with a WPF-application implementing a listview showing some events related to sleep medicine. I’ve created a simple model with a collection of various data. This model is the data-provider for a ViewModel which is databind to this view:

So far, so good; worked pretty easy. I then read something about the graphical ability of WPF, which should be very bad in displaying a lot of graphical objects. Again, I wrote a sleep-medical-application, but this time showing some random biosignals with events:

The problem here was the very long signal build of thousands of Polyline-segments. And indeed, this brought WPF to its knees. You can’t show some signals with the pure use of WPF-technology. I instead used GDI+ inside of a Canvas-element for the signal and the VirtualCanvas-technique for the events (read here about it). With that I managed to preserve databinding on the modifiable objects (the events): you can move them around and change their duration by dragging their border.
In a second step, I combined the model of the ListView with that of the biosignals and injected it into its ViewModel. Of course, every ViewModel is being unittested – what a wonderful world:
Sunday, May 17, 2009
Thread-Threat

Using lock = _interop.Lock
' do something with lock.ComInterop
End Using

Friday, March 20, 2009
Mix09 and "The Guide"
I recently finished The Application Architecture Guide 2.0. Now I can design every system from a mobile app up to a RIA :)
Wednesday, November 26, 2008
Book review "Essential Software Architecture"
Wednesday, November 19, 2008
Book review "Effektive Software-Architekturen"
Here are a few links I want to check out: Buschmann et al 96: A system of patterns, Bass et al: Software architecture in practice, pacman03.pdf.
Tuesday, November 11, 2008
Book review "Handbuch der Software-Architektur"
Now I'm reading "Effektive Software-Architekturen". The introduction is very amusing with a comparison between the "Wasserfallmodell", "V-Modell" and agile methods (hier unbedingt lesen).
