Blissful Designer – Blog of Jovan Stanojlovic

.NET Development and Web Design sprinkled with random thoughts on technology and art from a Toronto-based developer.

Archive

Category: Tutorial

Version Control (or Revision Control or Source Code Management) is still a somewhat of a mystery to many developers, especially those who are new in the field of software and web development. I am stumped as to why that’s so, because one figures that professors would advise their students that additive backups are an Extremely Good Thing. What does additive backup mean? It’s very simple.

Quick overview of how it works

By using an additive vesion control system, you will never lose your files, because nothing can be deleted, it can only be revised. Each revision marks a change (adding files, modifying files, removing files)  in the version control system, and the system keeps all the files of all revisions (these are highly compressed, so little to no space is wasted between revisions). Every revision is added on top of the last once, hence the name additive. At any point in time, we can go back and access the files from our previous revisions. All of your files are kept in the system’s database, called a repository.

Why use it?

This is a very good question. How do you benefit from version control system? Whether you are a programmer or not, and whether you are storing source code, pictures, music, or any other type of file, a version control system is an indefinite backup system. There is really no way to accidentally delete files or to overwrite them (assuming you’ve backed them up first!).

A lot of the times what people do is they will store their backed up files in:

  • a folder on the computer
  • a password protected zipped file on the computer or on a remote server
  • a USB key

And this is just counting the people who do back up their sensitive data!

The problem with all these methods is that they are prone to human error that cannot be undone. Version control does not suffer from this problem because if you make a mistake, you can always go back to a previous point in time, effectively undoing the changes.

Where do I get it?

There are a number of version control systems, each with pros and cons. The one that I use and highly recommend is Subversion (SVN). It is painless to set up, and you can get it up and running in less than ten minutes. The easiest way to set it up is to download the CollabNet Client and Server Installer. Afterwards, I highly recommend you download TortoiseSVN, providing you with a GUI on Windows accessible with right-mouse click.


Update: A number of readers have also recommended VisualSVN Server — a self-contained SVN repository manager. This is another excellent choice for both personal and commercial use. The free version comes with a few restrictions, but it’s definitely not a deal breaker.


It’s really that easy

For more information, TortoiseSVN provides a very good introduction and manual on managing your Subversion repository.

Conclusion

Try to use version control with all your important documents. This will ensure that your files never go missing, and in case of accidental loss of data, you can always go back to a previous version of the file. Ocassionally, it’s a very good idea to backup the version control system to another computer (password protected by default), in case of a catastrophic hardware or operating system failure.

When we try to find solutions to problems, we often think about things or scenarios similar to the problem at hand. As with everything else, software is no exception. For the majority of developers, the problem will boil down into this:

  1. Obtain user input
  2. Perform calculations
  3. Read or write information to a data source, and
  4. Ask the user for more input.

Although this scenario has been around for decades, and is one of the most common patterns developers face writing any kind of application, they are unaware of an elegant way of writing the application’s architecture.

The answer of course lies in a multi-tier architecture approach, which lets us write each of the three main functions of a program as independent modules:

  • Get user input
  • Perform the calculations of the program’s problem domain
  • Store or retrieve data in some long-term database

The multi-tier architecture can be further defined as a three-tier architecture, that contains the three modules as the main focus of the application’s architecture.

Lets look at the modules individually.

Presentation Layer

To the user, the presentation layer is the application itself. It is what the user sees and interacts with. To a developer, it is the layer where all of the GUI code will need to be written that allows the user to interact with the other layers.

It is important to realize that the presentation layer is just as important as the other two layers — and often times, even more important. Proper user interface design is essential in allowing the user to navigate and use your program with as few hurdles as possible. Unfortunately, a lot of developers do not follow guidelines, and more often, theme their applications without understanding the purpose behind theming. For Windows-based applications, it is essential to read the Windows User Interface Guidelines.

The presentation layer is most well known for it’s event handlers when dealing with user requests.

Business Logic Layer

This layer’s responsibility deals with solving the problem domain. The problem domain is another way to state the task which the application is meant for, the business logic. Does it calculate insurance rates based on some criteria? Does it schedule client appointments? These kinds of questions fit into the problem domain.

At this layer, most of our case scenarios become apparent through our classes and data structures. Often times, a BankAccount, Customer, Manager, or Service class will be present.

Often times, it useful to document the interaction of the components within the business logic layer, especially if they are complex (but it’s even more useful to make them simple in the first place!). Visual algorithm explanations like flow charts and state charts are very useful in getting a good idea of how this layer works.

The business logic layer is most well known for it’s calculation-intensive functions.

Data Access Layer

Often times the most intuitive and simplest layer is the data access layer. The sole responsibility of this layer is to read and write data from and to a source. The source is almost always a database of some kind. For our purpose, lets use MySQL as a popular database choice. The logic of the data access layer is as follows:

  1. Receive a request from the business logic layer asking for some data
  2. Retrieve the data, job done
  3. Receive a request from the business logic layer asking to insert some data
  4. Write new data, job done

Although simplified to a point, it is not unreasonable or uncommon of a data layer to function in this exact way.

It is often times helpful to abstract away the data source, so that the rest of the application is unaware (and rightfully so) of where the data is stored. The side benefit of this is that we can re-write the data access layer to use another source, but the interface between the data access layer and business logic layer will remain untouched.

The data access layer is well known for long-term storage, availability across different mediums and environments, and constant read/writes from and to the storage medium.

Putting It All Together: Application Controller

For most of the desktop-based applications, an Application Controller is needed. Because there are very few ways to intuitively write a three-tier application on the desktop, we need a controller that will take input from the presentation layer, call a business logic layer method, which in turn will read/write data, and finally, present the results to the user once this is finished.

The three-tier architecture is best present on the web, where the presentation, business logic, and data access layers can be completely remote and controlled by a framework designed for this kind of usage, such as ASP.NET.

Example Application in C# with WinForms.

To show the three-tier architecture in practice, I have written an example application that displays a collection of customer information in a table, using WinForms as the GUI framework and Access 2007 as a single-file database. It is thoroughly commented and highly recommended that you go through it to understand the application of the three-tier architecture better.

Download Example Application for Visual Studio 2008 (118 kb, Includes Source and Release Build).

Conclusion

The three-tier architecture is not a new concept. It has been used for decades, but many developers are still not taking advantage of this simple, intuitive architecture-level design pattern.

The most important thing to understand is when and when not to apply this type of design. As already mentioned, if your application is doing

  1. Get user input
  2. Process data
  3. Store and/or retrieve data

you would strongly benefit from this design pattern.