Article 17 - Technical Interview Questions - Design Patterns

Have you flustered in a recent technical interview or are you preparing for an up-coming interview? Many high-tech companies are screening candidates using textbook questions before bringing them in for further interviews. This article contains typical design pattern questions that interviewers will ask. Pay attention.

Singleton Pattern

The singleton pattern permits only one copy of the particular class to be instantiated. Thus, there should only be at most one instantiated object at any given point in time. This fundamental question is not difficult to solve. Simply declare the constructor as private and provide a visible method to instantiate the object. The separate method will then check for the existence of the object before creating one.

Singleton Pattern.

Interviewers may touch up this question by adding concurrency conditions. In Java, one can easily include concurrency by adding the word "synchronized* as part of the method signature. However, this does not work for static methods, which is typically used in the Singleton Pattern. In this case, simply have a private static field that is instantiated statically. Then in the method, you can return this singleton object concurrently. But the problem becomes even harder if the interviewer requires that the object be instantiated lazily; otherwise known as Lazy Instantiation, another design pattern.

Concurrent Singleton Pattern.

As a follow up, you can synchronize on the field declaration of the singleton object in the code block where the check is and then return.

Optimized Concurrent Singleton Pattern with Lazy Instantiation. Note the double check.

Observer Pattern

The Observer Pattern is a typical push and subscribe design. Here, we have a set of subscribers that want to be notified of some events or messages that is published by the publishers. This design is often used for asynchronous designs such as mail systems. It can also be used in user interface designs.

Strategy Pattern

This pattern is very useful for encapsulating detailed and complex implementations while abstracting a common interface. It is widely used.

For example, a sorting class my consist of many types of sorting algorithms, which includes quicksort, bubble sort, and others. We can abstract an interface that a user can call, such as ".sort()", which in the implementation, we can dynamically swap the algorithms that perform the sort. For example, using bucket sort for numeric input, and quicksort for all other sorts.

You should be able to ace the interview.

Comments (27)

Posted by anonymous - Bian at Thursday, May 31, 2012 12:40 AM

I have learned quite a few imptorant things via your post. I might also like to state that there can be situation that you will have a loan and do not need a co-signer such as a Government Student Aid Loan. When you are getting a loan through a common loan company then you need to be able to have a co-signer ready to allow you to. The lenders will probably base any decision on the few factors but the largest will be your credit ratings. There are some financial institutions that will additionally look at your job history and come to a decision based on that but in many cases it will depend on your scores.

Posted by anonymous - mulberry outlet at Sunday, November 18, 2012 2:29 PM

Very interesting subject , thanks for posting . "The great leaders have always stage-managed their effects." by Charles De Gaulle.
[url=]mulberry outlet[/url]
<a href="" title="mulberry outlet">mulberry outlet</a>

Posted by anonymous - Lose Stomach Fat at Monday, November 19, 2012 2:06 PM

Wonderful web site. A lot of helpful info here. I am sending it to several buddies ans also sharing in delicious. And certainly, thank you for your sweat!
[url=]Lose Stomach Fat[/url]
<a href="" title="Lose Stomach Fat">Lose Stomach Fat</a>

Posted by anonymous - ugg classic short at Monday, November 19, 2012 3:18 PM

Some genuinely wonderful articles on this website , regards for contribution.
[url=]ugg classic short[/url]
<a href="" title="ugg classic short">ugg classic short</a>

Posted by anonymous - mulberry at Tuesday, November 20, 2012 5:18 AM

I just couldn't go away your web site before suggesting that I extremely enjoyed the usual info an individual supply in your guests? Is gonna be again frequently in order to investigate cross-check new posts.
<a href="" title="mulberry">mulberry</a>

Posted by anonymous - buy bags at Wednesday, November 21, 2012 10:47 AM

I dugg some of you post as I cogitated they were very helpful very helpful
[url=]buy bags[/url]
<a href="" title="buy bags">buy bags</a>

Posted by anonymous - cheap camera at Thursday, November 22, 2012 4:21 AM

I dugg some of you post as I cerebrated they were very useful very useful
[url=]cheap camera[/url]
<a href="" title="cheap camera">cheap camera</a>

Posted by anonymous - supra tk society at Thursday, November 22, 2012 6:46 AM

I dugg some of you post as I cogitated they were handy handy
[url=]supra tk society[/url]
<a href="" title="supra tk society">supra tk society</a>

Posted by anonymous - Christian Louboutin online at Thursday, November 22, 2012 3:16 PM

Very interesting points you have observed , regards for putting up. "The judge is condemned when the criminal is absolved." by Publilius Syrus.
[url=]Christian Louboutin online[/url]
<a href="" title="Christian Louboutin online">Christian Louboutin online</a>

Posted by anonymous - UGG ???? at Thursday, November 22, 2012 6:06 PM

I dugg some of you post as I thought they were extremely helpful extremely helpful
[url=]UGG ????[/url]
<a href="" title="UGG ????">UGG ????</a>

Post a comment

  • Name:
  • Post:
  • Challenge:

Register or login to post comments easier.

Vantasy World Copyright 2011 - 2017. Vantasy World is a project developed by Vantasy Online. Privacy Policy.