Chain of Responsibility JavaScript Design Pattern

Today, we’ll be talking about the Chain of Responsibility Pattern. This pattern decouples the sender and receiver of requests. This is done with a chain of objects that can each handle the request itself or pass it on to the next object. Confused? Read on.

Chain of Responsibility Structure

3 parts make up the Chain of Responsibility pattern: sender, receiver, and request. The sender makes requests. The receiver is a chain of 1 or more objects that choose whether to handle the request or pass it on. The request itself can be an object that encapsulates all the appropriate data, or it could just be a normal function call on the receiver with no arguments.

Senders send the request to the first receiver object in the chain. The sender only knows about this first part of the chain and nothing about the other receivers. The first receiver either handles the request or passes it on to the next receiver in the chain. Each receiver only knows about the next receiver in the line. The request will continue down the line until the request was handled or there are no more receivers to pass it on to, at which point either an error is thrown or nothing happens, depending on how you design your chain.

Chain of Responsibility Example

For our example, we’ll be creating an ATM. The chain is going to consist of different sized dollar bills. When you ask for some cash, the machine starts at the larger bills and pulls out as many of those that it needs, then moves on to the next smaller bill and so on until we’ve got all of the money or we run out of bills. This example is purposefully simple, because that helps to show the concept more clearly without diluting the code with too many example-specific implementations.

We’ll start by creating the receiver ‘class’: MoneyStacks. Normally this would just be an interface that would be implemented by different receivers, but this example is simple enough that the only variance between each of the receivers will be the size of the bills in the stack. We’ll just set that number via a parameter in the constructor.

My Mistakes as a Web Design Newbie

Learn from them

Approaching retirement age I was made redundant last year and decided to create my first web site, initially knowing little about it. I hope that, by reading about my experiences, I may save you both time and money if you ever find yourself in the position of wanting to build a site with little initial knowledge.


I bought five or six ebooks on how to make my web fortune from the one-page web-sites that you see on the web. The prices ranged from $9.95 to $29.95. It would be unfair of me to say that they were of no use, as you can always pick up the odd pointer, or contact. However, with the benefit of hindsight I would not have purchased any of them. Instead there are free, better written books which give you at least the same pointers, and often have more substance. You can download from my web site, for free, two excellent books by Ken Evoy, which will provide you with a good basic knowledge to move forward. Don’t get carried away with the sales hype contained in some of these “get rich quick” single page sales letters that offer huge free bonuses and an imminent price increase.

Universities and colleges

There are various colleges and universities on the web which promise you the ultimate in web creation, site marketing, search engine optimization and much more, “all under one roof” They usually have libraries of “how to” books and membership is by monthly subscription with some offering a lower fee for the first month. Have a look, by all means, I looked at three and claimed my refund within the stated period. I found that I could obtain similar information offered for free with a little searching, and that what they really offered was convenience.

Web Design software

I initially purchased a web site building package for $69.95 and was soon disappointed by its lack of functionality. I then looked over the shoulder of a friend whilst they showed me the workings of a top-end product costing nearly $400.00 but I found it to be too complicated with too steep a learning curve too be quickly productive. I posted a request for help on the Warriors forum and there were more recommends for a particular product than any other. So I decided that my first web site would be a review of that product, which I would create as a trial, before I went on to build a site that would aim at generating income.

What should the web site be about?

Several of the books that I read suggested that the subject matter should be about something that you enjoy doing and therefore you will create your site with more passion and enthusiasm. Whilst this is sound advice I found that the need to create a trial site, which would force me to learn the basics, was more than a sufficient driving force.

Domain name & Web hosting

Go for a dot com registration and pay no more than $10 per annum. Don’t go for free hosting, you get what you pay for. I looked at hosting sites that offered complete package with hosting, autoresponders, SEO and linking software and much more. Whilst everything was conveniently in one place they failed to convince me that each product would stack up well if they were competing in each niche market. I therefore opted for the best of breed approach and a little less convenience.

Search Engine Optimization

This was probably the subject that I was most worried about as I new that it referred to making a web site as easy as possible for the search engines to find, but I had no clue as to how to go about it. I have a free ebook that you can download entitled “Search Engine Optimization Made Easy” which will give you the basics to carry out this process. The book is really a plug by the author of SEO software for his excellent product. I was fortunate in that the web design software I selected also, somewhat unusually, held my hand through this process, carefully pointing out page, by page, what I needed to do.

Article Distribution

I was aware that, in order to succeed, I should submit articles to the numerous Article Directories present on the Internet. There are two ways to do this. By purchasing one of the two major pieces of software to assist me in doing it myself, or to use a company to do it for me. I looked at each way and found that, whilst both software solutions cut out some of the tedious manuals tasks of submitting to over 150 directories, it was still time consuming. Having examined the market place carefully, discounting any company who charged for a fixed number of submissions, I opted for one who for a fixed quarterly fee would submit any number of articles.

Link software

Again, so that I would get more site traffic, I new that I should get other sites to link to mine and that I would have to manage those links and the emails back and forth etc. I initially started to design an Excel spreadsheet linked to Microsoft Word but decided that I would still have to create the links pages by hand. My advice is to obtain software which houses all your links in a searchable database, handles all of the emails, including template housing, and that automatically creates the HTML link pages for you.

Designing Sites For Search Engines and Directories

In terms of layout, many web sites are not designed for optimum search engine and directory visibility. People or companies seem so centered on their corporate or personal images, products, and services that they neglect to design their web sites with search engines and directories in mind.

Search engines and directories vary in the way they rank your web site in a search query. Some search engines place primary emphasis on the text within your title tags. Some search engines place emphasis on the main ideas presented in all of your text on a single web page. Some directories emphasize the text you submitted in their “Description” field. How and where you place your text, both in the copy your visitors see and within the HTML tags your visitors do not see, will affect your ranking.

Keyword selection

Of primary importance is selecting the best keywords for your industry and the keywords you believe your potential customers will use to find you. Selecting the right keywords requires research.

Look at your company’s printed materials. What words do you use over and over? When you speak to new and current customers on the phone, what questions do they frequently ask and what words do they use? Ask your current customers how they would find you on the Internet. Then go to the major search engines and directories. Type in the keywords you want to use. Study the source code of the web sites that appeared in the top 20. Look at how your competitors ranked in a search query. Adjust your keyword selection accordingly.

Keyword placement

Of equal importance is keyword placement on individual pages. The text in your title tag is one the most important elements for ranking well in search engines. The text in your titles should be descriptive, using the words and lingo in your industry, and should accurately reflect the contents of each web page.

For optimum search engine positions, your keywords need to appear at the top of your web pages. Thus, before you design your web page, ask yourself if you (or your web designer) have strategically placed your keywords within your title tags, meta-tags, headings, graphic images, and the first paragraph within your body tag. If not, you might need to rethink your site design.

Keyword frequency

What is important to both the search engines and your target audience is keyword frequency and keyword prominence. Designing and coding your site with keywords in the right locations and the right frequency is an art form. Keywords need to appear frequently on your web pages, but if they appear too frequently, your site will be penalized for word stacking (also known as “spamming the index”) or could be removed permanently from the index.

Also, some search engines ignore meta-tags. Thus, if you have included your keywords in your meta-tags but have not placed them elsewhere, you have missed a huge target audience, namely AOL users. Sites with frames have problems being indexed well because there is little opportunity otherwise to include additional text with keywords.

Very, very few web sites can get in the Top 10 of all the major search engines (AltaVista, FAST Search, HotBot, Google, Lycos, Teoma) without spamming. We cannot emphasize this enough: if you hire anyone (a submission service, an individual, an online promotion service, etc.) to do the services we just described, they need to have both HTML and design experience, online marketing, and excellent copywriting skills. You do not want your web site to be permanently banned from a search engine or directory due to ignorance or lack of experience. Furthermore, submission services usually do just that: submit. Many do not perform keyword research, the HTML coding, and copywriting necessary to get a site optimally placed within the search engines. Ask a lot of questions before handing over any money.

Link and site architecture

Placing keywords throughout your web pages is useless as a search engine marketing strategy if the search engine spiders are unable to record the text on your web pages. Therefore, always have a link architecture on your site that the search engine spiders can follow. Oftentimes, this means having two forms of navigation on your site: one that your target audience prefers, and one for the search engines.

Site statistics

For the first few months after you have your web site submitted to the major search engines and directories, you should see a jump in traffic. If you look at your site reports with your visitor statistics, which should do frequently, you will see when the search engines spider and index your site.

Hopefully, because you have been thoughtful enough to give potential customers a reason to return to your site again and again, people will bookmark your site, and your web statistics will show an increase in a “No Referrer” category under referral URLs. Your site reports should show you where your potential customers are coming from (i.e. which search engine or directory they used to find you) and which keywords they used to find you.

After your site has listed in the search engines and directories for a few months, review your site statistics and determine where the majority of your traffic comes from. Then focus your advertising efforts on those directories and search engines. You get better sales from targeted marketing than from spreading your net too wide.

One client did exactly what we recommended, from keyword selection to monitoring site statistics. They found most of their sites referral traffic came from Yahoo queries. They bought banner space from Yahoo for two months. Whenever two of their keywords were typed in a search query, their banner would appear. Their traffic increased over 500%, and their sales reached five figures per month.

Landscapers Website Design

If you are in the landscaping business, you need Landscaping Web Design. The opportunities for your business are unbelievable on the web. Even in small markets, your customers are looking for you on the web. They want to see the projects you have completed, the designs that you have created and all of the positive things your customers are saying about you.

It is important to understand the importance of a web presence for your business. The yellow pages are reaching a much more diluted mix of people and the fact is the price keeps going up. Year after year the competition gets thicker, margins seem to get smaller and it becomes harder and harder to differentiate your business from your competitors. The Internet is the opportunity of a lifetime. I’m not suggesting that you terminate your yellow page ads completely, but what if you could have a top class website to refer people to from the phone book? It absolutely creates the difference in being washed away by your competitors, over sized, over priced ad, and the prospect selecting you instead because he was able to see the expertise of your work on your website. The yellow pages only offers you a single page, and heaven knows what a full page in the yellow pages costs, while the web offers as many pages as you would like or need in order to pre-sell your customers before they even call you to set up an appointment.

We have seen it time and time again, customers who have clicked on a properly designed landscaping website and been sold before they called to get a price! It’s true. When you build a website, it is important to gather all of the important information. Things that a sales person would normally take to a sales call, like glossy foldouts, marketing propaganda, before and after photos and a list of testimonials from customers that are head-over-heals in love with projects that your company has done. Add to this the proper keywords and the research to insure where the market is and poof, you have a successful web site.

How to make your web site work.

It is important to incorporate everything that you need in your site to capitalize on traffic that is free. Meaning search engine traffic, directory traffic and other complimentary traffic from non competitive sites. This is important because as you develop your web presence, you don’t want to have to spend hundreds or even thousands of dollars to buy clicks. It is much more cost effective to develop the site to incorporate the search words or key phrases that will garner the traffic target you’re looking for. Understand, the traffic cannot be general traffic. To use an old marketing phrase, the “shotgun approach”, is not an effective way to generate quality leads to your site. Try concentrating your search efforts in very specific customers that are actually in the act of searching for a company to solve an existing problem or handle a service that they need. You are looking for the needle in the hay stack and regularly find it. When building your site, don’t just brand your business, look for ways to go much further than that and have a quantifiable way to determine success. That being live prospects that find you in the search engines or elsewhere. Those prospects then come to your site, are given the information they need to make a buying decision through the content that has been provided on your site, and then engage you to close the sale. With the exception of the closing, all of this is done in an automated system. This dramatically shortens the sales cycle in almost all businesses. This is the difference, most web designers don’t understand the nature of your business. We have owned successful contracting and building trade businesses ourselves. We know how the Internet works and can share that with you. The fact is, most web designers are graphic artists. They generally don’t have any practical experience in running a contracting business.

Development of your website.

The development of your website is done with basic input. Gather information that is necessary to build a story or theme for your site. For example, if you are a general contractor and your specialty is churches as an example build the content of the site around the construction of churches. Not that churches would be the only topic for drawing traffic, just one on many. Let’s say for example you’re an HVAC contractor and you specialize in duct cleaning. The focus topic on your site might be duct cleaning. Each site is different in its development of a theme.

We developed a site for a paving contractor that had the specialty of municipal work. Their site was developed to have focus on who we were going to have as visitors, municipal buyers. Based on who your target is and what service or product you are marketing to them will ultimately determine what the content of your site is.

Sharing infinite amounts of information without additional cost!

What about delivering information to existing customers & prospects? Think of it this way, how much does your company spend in glossy marketing handouts and other printed literature in a years time? What if you could deliver, to your customers and prospects, a way to get updated information that may drive them to engaging a new service that you provide or a new product? What if you gathered not only US Postal service addresses, but also email addresses that allowed you to share, in a captive way, your goods and services repeatedly to your customers and prospects? Delivering your entire marketing plan in a web format will dramatically reduce your annual printing costs along with increasing the number of touches you can have with a prospect or customer with basically no incremental cost to you. Imagine your closing percentage doubling or more! We have clients that have no other marketing budget other than their websites. They’re marketing impact is dynamic because as traffic is generated, leads are extracted. Even if those leads aren’t at the point of buying, they have in most cases captured their contact information through the use of a “free information” form. With the contact information in hand, the site owners can then take a much more direct approach to selling the prospect on the services or products sought. It is a marketers dream. Prospects that tell you what they are looking for or are in need of, giving to you, and then giving you permission to market to them directly via email! We have developed auto responders that will in some cases, based on the information that has been requested, send an automated response or series of responses to that prospect that deliver the specific information they have requested while still captivating their contact information for future follow up. Email is rapidly becoming as powerful if not more so than direct mail has been for quite some time. Building an email customer list will be imperative to all contractors success in the coming years. As your email address list of customers is building, you have the opportunity to contact them with new, unrelated information about your company and the products and services that you offer. And the contact is basically free, meaning you have no postage expense, no list expense because you have built the list yourself, and no printing expense because there is no need to produce thousands of printed pieces. Understand, if you’re not marketing to the Internet, your competition surely will. It is better to beat them to the market and build a presence sooner rather than later. Establish your company as the leader in your field.