How to Choose a Design Pattern That Fits
In the case of crumbling supports you have identified a hole in your design. So what do you do with any hole? Search for the right size shape to plug it! Here's how.
Describe the hole your design pattern will fill
What type of hole is it that sits in your design? Since you are looking for a design pattern to fill the hole describe the problem as it relates to the three types of design patterns; creational, structural or behavioral. The goal here is to identify and narrow down the list of possible design patterns. So, is your problem a creational one? A Structural one? or a behavioral one? Once you have identified the type you have narrowed the list of options by two thirds.
How to identify the problem
Here are some tips on determining what type of problem you have.
Creational - If you are trying to separate the process of object construction and object use. Typically patterns like the Singleton, Factory, Abstract Factory and Builder Structural - If you are trying to interface to a sub-system, connect to an interface your system doesn't support or provide a flexible storage structure for adding and manipulating objects. Adapters, Bridges, Composites and Façade's are good examples Behavioral - If the primary concern is how you access objects, perform operations on them and otherwise interact with them consider patterns like the Command, Iterator, Observer, Strategy and Visitor
It should be noted that the list above is far from exhaustive. Just an example of what you might be looking for.
Determine your primary intention
Once you have worked out what type of pattern you are looking for you need to delve into your design a little further and decide what your primary intention is if that hole were to be filled. Here's an example I encountered recently:
I was pulling out a large amount of information from tables in a database and ultimately wanted to convert this information to xml, keeping any hierarchical information that was present in the database in the form of relationships. These hierarchies would then be used to define the level of nesting in the xml structure.
The tables retrieved would not always be the same and the xml structure would have to reflect this. Having ruled out using a persistence framework like hibernate or ibatis knowing that I could implement a much lighter solution, I then proceeded to create simple mapping files for the tables I was pulling out. This is where I found my hole. How do I structure and store this information in a manner that will reflect the final xml structure? To cut a long story short, the database tables I modeled as hashtables and used the Composite pattern to create the structure of composite components I was looking for.
In the aforementioned example the intention was to structure and model the table representations in a flexible hierarchical structure. The composite pattern provided a flexible means of nesting tables within each other thus preserving this structure.
Match your intention with that of a design pattern
Now that you have worked out the category your problem exists in and you have identified the principle problem you are trying to address you can begin exploring for a pattern that is designed to match the intention you are trying to fill. Most design patterns books describe patterns in this way; it then simply becomes a task of matching your intention with that of a pattern.
If you have identified your intention correctly and cannot find a pattern to match, don't fret. Your hole just may not be pluggable by a design pattern. Design patterns address problems that occur over and over again and provide a solution to the core problem so that this solution might be replicated over and over. It may be the case that your hole is not one of these problems that occurs over and over again and thus does not have a repeatable solution. It may just be an oddly shaped hole!
In summary, let your design stand on its own for a while first and see if there are any glaring spots in your design that are asking for further scrutiny. Describe the type of hole or gap in your design with respect to the three common design pattern types; creational, structural and behavioral. Once you know the type, state your intention as if it were to be filled and match it with the intention of a pattern in this category. In other words, don't choose the design pattern. Let it choose your design. The more familiar you are with the various design patterns and the more situations you have used them in the quicker you will become at spotting them in future designs.
This was meant to serve as a guideline to identifying patterns to fit design problems when you have discovered a pattern may be useful. It is just that, a guideline. In the next article in this series I will look at how to actually use a design pattern in your design once you have discovered the need for it.
Related Tags: software, design, patterns, software development, solving problems
Joshua Hayes
http://codelines.net.au
Software Developer
Recent articles in this category:
- Improper Way Of Marketing Reflects Poorly On A Company.
New business, product or service everything requires visibility, awareness in order to come into the - Replacing Paper Prints With Online Versions
Nowadays saving out on resources and being additionally informative are both aspects that are in. In - Stop Smoking Effectively
If I told you of a way that you could stop smoking harmful tobacco would you believe it? Most people - What Is Runtime Error 182? And How To Fix It
Are you finding an effective way to fix runtime error 182? Do you think fixing runtime error 182 is - Do You Know How To Fix Runtime Error 87 In Minutes?
Are you finding an effective way to fix runtime error 87? Do you think fixing runtime error 87 is to - Knowledge About Avi, Avi Player, Avi Converter On Mac
Knowledge about AVI, AVI player, AVI Converter on MacWhat is an AVI?AVI, an acronym for Audio Video - Buy Your Highly Successful Email Survey Software Today
Email Survey Software- Boost Your Business and Increase ProfitsAn email survey software could be one - Xrm - The Anything Relationship Management Solution
I recently attended the Microsoft Dynamics West Region FY11 Sales Planning Retreat. This year's meet - What Are The Benefits Of Working With Electronic Medical Records
Recording medical information is a vital part of health care services. These records are necessary f - Basic Factor To Make Website Business Oriented
Internet is home for millions of websites. The online business is becoming more and more competitive
Most viewed articles in this category:
- Parental Control Software
Parental control software is software that can help parents protect their children when they are onl - Digital Asset Management Software
Managing and organizing your organization's documents is a critical component to your business's suc - AdobeRGB vs. sRGB
Understanding color spaces I'll try to explain it very simplified, but understandable for everyone - Confessions of a Prankster
I wanted to get a jump on April Fool's Day, partially because of the long, cold winter blues, and pa - Malicious Thoughts About The Spyware Ills Of My PC
Who would think I was capable of such revengeful thoughts about the parties responsible for inflicti - Recover File and Recover Deleted File Tools
Data recovery software is a very effective way of retrieving data from a worn or damaged hard disk d - Life without Windows
Ubuntu, a user-friendly version of Linux, has been running so nicely on my home PC that I decided to - What Benefit Does an Online Software Download Site Offer You?
Are you having a problem that where you find a good softeware when you consider to have a try or wan - Maintaining A Website
There was an era when people were talking about how to create a website using html coding or some ea - Benefits Of Proper Time Tracking
Have you ever written down time when you have started and finished your work? Maybe you have had mul