Posts Tagged ‘Separation of Concerns’

Maintainable MVC Series: View Model and Form Model

Wednesday, March 3rd, 2010

This article is part of the Maintainable MVC Series.

As mentioned in the previous post all views are strongly typed and every view has it’s own View Model. Although this results in quite a lot of classes the upside is maintainability in that it’s very straightforward. Every bit of data displayed in the view has a corresponding property in the View Model. As soon as it’s no longer needed in the view we remove the property as well.

Of course, it sounds like it’s in opposition with the DRY principle (Don’t Repeat Yourself). However the data in the properties of the view models stems from the domain model, meaning the business rules are still in one place. To get the data from the domain model to the view models we have mapper classes in the presentation layer.

(more…)

jQuery: performance of DOM manipulation

Saturday, February 14th, 2009

I tried moving some html that didn’t have a direct relation to the meaning of my content, but more with layout aspect, to the client-side by writing a jQuery plugin for it. This in order to heighten the separation of concerns. The plugin performs some DOM manipulation in order to apply a drop shadow effect as seen in the following image (left side without plugin applied, right side with):

image-before-and-after-shadow-plugin

To accomplish this the crucial part of the plugin performs the following DOM manipulation:

elementToWrap.html(
	'<div class="frame" style="width: 157px;">' +
		elementToWrap.html() +
		'<div class="right_shadow">' +
			'<div class="shadow_top_right"></div>' +
			'<div class="shadow_right" style="height: 93px;"></div>' +
		'</div>' +
		'<div class="bottom_shadow">'
			'<div class="shadow_bottom_left"></div>' +
			'<div class="shadow_bottom" style="width: 143px;"></div>' +
			'<div class="shadow_bottom_right"></div>' +
		'</div>' +
	'</div>'
);

(more…)