Written by nitinpai on June 10th, 2007
Design Patterns – Building blocks for your application
What is a pattern?
A pattern in short is a time and tested answer to a specific problem. When the design phase for an application starts a group of analysts sit with the developers to discuss about the requirements and come out with a proposal for a design.
The design thus formed is always taken care for being not only useful for the current set of requirements but also for the future.Any assumptions that can become realities in the future are introduced right in the beginning so that there is not much change involved in the code if it actually happens. Care is taken to make it as modular as possible to be easier to work with.
How do patterns come into being?
Patterns help in such design making decisions so that the design is ready in lesser time and there is not much apprehension that it would turn out wrong. This is because patterns are nothing but the outcomes of the problems we frequently face. Someone somewhere might have had faced a problem which made him/her to arrive at a solution which was tested and proved successful.
Such solutions when spread across help in similar situations for the people worldwide since requirements to any applications are similar in nature most of the times. When such common solutions are documented properly they give birth to standardized nature of the same solutions. These in turn are called standard design patterns.
Patterns are involved everywhere. They might be related right from a small portion of the software application you are coding to the distributed applications used in the enterprise. Based on the nature and technique of the pattern they are categorized and used accordingly.
What are the advantages of adhering to design patterns?
Patterns have several inherent advantages in them. The first and foremost being that they are trustworthy and acceptable since successful implementations are already prevalent when you consider a standard pattern for your application. Thus you can be sure that the design you are making with the pattern in mind will actually work out the way it is expected for.
The only thing to be taken care is the execution of the pattern. Even this part is not much bothering since there will be frameworks which have been implemented with the concerned pattern and you are just supposed to include the framework libraries in your application code.
Besides this, the approach to a design involving patterns have the following benefits :
- Time Saver – Patterns save your precious time by already providing you with the blueprint of the solution. You just have to see the blueprint and design your application in a similar manner. Its as good as using a trace paper for making your mechanical drawings which is used most of the times when the drawings are complex and you don’t have time left to complete the assignments. The pattern would actually help you in answering your most complex questions in the least of time.
- Foolproof Design – Who would want the design to be scrapped after long hours have been spent on it to carefully map the requirements to the design. But no one is perfect and hence this applies to the design too! But if you consider a pattern to your design then you are in a position to not only stand by your design in a more confident manner but also make the managers approve by showing them the examples of successful implementations which have made the pattern a standard approach to the concerned problem. How cool is that?
- Change Intensive – An application is always time and forth surrounded to changes. These changes might either be related to the business to which the application is catering to or it might also be related to the change in technology which your application has to comply with. And who can ever bet that technology and business won’t change? The answer is simple, no one! By applying multiple standard patterns in combination you can be sure that such kind of changes wont harm in any way the behavior of your application. Because standard patterns come with flexibility being the prime concern.
- Ease of Maintainance – This is probably the most and the brain wrecking aspect when it comes to application design. When applications are designed it is of prime importance that the application should withstand time and tide and should also be easier to understand and maintain. This is simply because you won’t be associated with the application forever.In such cases it becomes necessary that the people who will take the application in their hands in future should be in a position to realize the design architecture quickly and start their work on it.
- Attractive Design – It is important that people should appreciate your design. And patterns are used to this exact effect. Since standard patterns and known to most of the people associated with the same environment it is a high probability that the design will be easier to test, learn and then maintain. During the testing phase too, the pattern makes it feasible to locate the point of crash if ever, in short time as the components adhering to a pattern are expected to work for the aspect they are meant for.
There might be many more advantages to be added to this list. Considering all these aspects it is always better to follow standard design patterns rather than having to sit over late nights and start to reinvent the wheel.
Designing with Standard Patterns
Best practices always help when you sit with a design in mind and patterns help you in realizing these best practices quickly. But in order to come to a conclusion of using patterns in your application design, the knowledge of all the existing patterns is a must. Or else you would be stuck upon a pattern which you knew but which would cater only to a partial module of the application than the entire application itself.
Knowledge of all the patterns, even maybe in brief, would help in coming up with an application design which may involve one or multiple patterns. And this would not only enrich your practical sense of going ahead with the design but also make you a skilled professional at analyzing practical problems and coming up with robust and quick solutions.
If you would like to know more on design patterns here are some good resources:
- Sun – Core J2EE patterns
- Javaworld – overview of J2EE desgin patterns
- Oracle – J2EE Design Pattern Samples