December 2008 - Posts

I recently read a new book published by Packt Publishing, “ASP.NET 3.5 Application Architecture and Design” by Vivek Thakur. I've noticed a lot of articles and blog posts about design patterns and domain models in the ASP.NET community but it really mystified me until I read this book. Although many of the blog posts I've read have tried to be an introduction to design patterns, I'd have to say they all did a poor job compared to Vivek Thakur's book which explains it all in plain English. I learned how application architecture applies to web development and what advantages it is meant to offer.

For example, the chapter on tiers and layers explains how the business layer, UI layer, and data access layer relates to namespaces and classes you could create to organize your project. The chapter on entity-relationships clarified how the domain model used in the object-oriented system may differ from the logical data model used in the relational database management system.

I also found good explanations of; lazy loading, to defer the loading of all properties until they are really needed, the singleton pattern, which restricts and controls the number of objects instantiated for a particular object during the application life cycle,  the factory method, used to create objects without prior knowledge of the object using interfaces, and dependency injection, which allows you to plug-in an implementation that satisfies the interface requirements. Although I've come across these terms before I had no idea what they meant or how they could apply to ASP.NET. You'll find some really basic examples of how you can write code to use these design patterns.

If you are an expert on application architecture and expect in-depth coverage of how to apply the factory method in ASP.NET then you'll be disappointed. I'd say this book is more helpful for someone like me, a developer who is completely mystified by what everyone seems to be writing about these days. That is not to say you might not pick up a few tips from the material. For example, page 137 mentions a lock statement that can be used to ensure thread safety and I'd never encountered that before.

I also appreciated the author's practical approach to design patterns. He does not recommend them for small projects. This kind of lets me off the hook because none of my projects could really justify the additional overhead of a loosely-coupled design. However that is not to say you won't encounter such design patterns in your work. For example, I'm currently trying to customize the Elgg open source web application for social networking and its database schema is a peculiar attempt to incorporate entity relationships directly in the physical data layer. In any event, you are not meant to directly access the database. Instead you should get a reference to an ElggObject and use its properties. 

I have not been blogging here because I've been doing a lot of web design research lately which does not involve ASP.NET. I'm really slacking off on improving my programming skills. I went on a fabulous vacation and never came back mentally. However I'm still making the effort to master web design so I will share some of my recent discoveries.

Yesterday I learned about the "computed style" in CSS. I don't know why I've never come across this term before now. There are so many little details in web development. I'm always finding holes in my knowledge. Any way, a computed style is the value a CSS property will have when the browser needs to calculate the value based on a percentage or a value relative to another value. For example, if you specify a div to have a width of 50% and it contains an element that inherits its width from the div, then that element will have a computed value.

I had to figure this out because I'm using the http://www.plaintxt.org/themes/sandbox/ WordPress theme as a template for a custom theme. The web design community seems to be very keen on WordPress. You can find many tutorials on how to design for WordPress. I was working on the header for my design and found it would not appear at the top of the page in Firefox. There was a gap between the top of the page and my header. I examined the layout in Firebug and saw a 16 pixel offset on the top of the header element:

I could not figure out where that 16 offset was coming from. There was nothing in my CSS to set any height to 16px. Eventually I tried the developer tools in other browsers. Opera told me that there was a top: 16px computed style for my header element. So I had to learn about computed styles and how to deal with them.

The height for a block-level element is calculated in CSS. If such an element has no height defined, it will be set to auto, which is the default height for block-level elements. You have to change the height of the div by either adding a border or a padding to avoid the computed style.

So to eliminate that computed value I had to add a little padding to the top. As you can see I did have its height defined so I don't know why there was still a problem.

   1: #header {
   2:     background: #FFFFFF url(images/header_img.jpg);
   3:     height: 145px; /* height of image */
   4:     padding-top: 1px;
   5: }
The following CSS property values will result in a computed value; ‘auto’, ‘inherit’, ‘50%’, ’smaller’, ‘1.5em’ etc.
More Posts