Portfolio of Pieces
The benefits of modular design.
Let's face it, when starting a new project everyone wants to find a quicker way to get things done. A developer is no different. Of course, coding is what we do. But what if you could find a way to write less code, get your project done faster and still do an impressive job?
That's where reuse and modularity can help.
Whether it's creating a shared library of commonly used functions, or using third-party components, the benefits of code reuse are clear. However, one commonly overlooked area is the user interface (UI). The UI layer of your application is generally the most time-consuming aspect of the entire development process, so reusing prior work is imperative if you want to maintain a healthy bottom line.
Building a UI using a modular design allows you to swap pieces in and out. There are varying degrees to which you can go, and as with everything in software development, there are tradeoffs as well. The truth is that in order to design for reuse, more resources are required up front, with the payoff coming later as you begin to reuse the previously developed bits. At the simple end of the spectrum, controls and components -- grids, trees, menus -- are reusable "modules."
On the more complex end of the spectrum are Model View Presenter (MVP) patterns, such as those implemented by Microsoft's Composite Application UI Block (CAB) framework for smart client desktop apps. MVP models promote a high degree of modularity in an application by separating the presentation layer from the business logic beneath it. Again, the tradeoff is the work required up front.
Where you choose to land in this spectrum is determined by the size and scale of your application. As applications begin to scale in size, using an MVP pattern becomes much more appealing. However, for a quick and dirty app, the overhead of MVP will almost certainly outweigh the benefits.
In application development today, building a UI with components is commonplace; whether you're using the controls that shipped with Visual Studio, working with third-party components or rolling your own. Even though components wrap up a great deal of functionality into a reusable block, there's always room for improvement. One area with great potential for reuse is styling.
For example, if you're doing ASP.NET development, be sure to look for components that can be styled through an external cascading stylesheet (CSS). Aside from the reusability aspect, external stylesheets offer additional benefits in that they can be created or modified by non-programmers. Because the CSS is separated from the code, designers can style the application without interfering with the developers. Even if you're not using a separate design team, the ability to change styling attributes without opening up the code is a very healthy benefit.
Unfortunately, if you are using Windows Forms components, CSS is not an option. You'll want to be sure that the components you're using give you the ability to separate the style or design layer from the code. By separating the style from the code, you're protecting yourself against high maintenance costs. It's not unheard of to rebrand an application after it has already been deployed for years. In most cases a re-brand is a costly project that involves opening up the code, rebuilding the app and re-testing the entire package. That said, re-branding an application without modifying the binary portion is an exciting prospect. Not only do you not have to worry about finding developers who still remember the code, it's not even necessary to go through a testing cycle because the binary portion of the application isn't being modified. The result is low stress, and more importantly, low cost. This wouldn't be possible if your styling was tightly integrated at the code level.
To demonstrate the power of this idea, take a look at Microsoft's latest platform, Windows Presentation Foundation (WPF). Core to WPF is the separation of the style or design layer, through the declarative XAML file.
By breaking down the UI into smaller, reusable pieces, you can begin to leverage the benefits of modularity. Not only does this speed up development times and improve code quality, it also helps to keep maintenance costs down after the application has been built-an area of the application lifecycle that is often overlooked.
Modularity itself isn't a magic bullet that will guarantee that projects get done on time and on budget, but it does enhance your ability to craft sensible, elegant and efficient code that will be much easier to manage down the road.