More Pattern & Practices Interview Questions Part 1 | Part 2 | Part 3 | Part 4

Design Pattern & Practices Interview Questions and Answers (103) - Page 1

What is Prototyping?

Prototyping is the process of quickly putting together a working model in order to test various aspects of a design, illustrate ideas or features & gather early user feedback. It is believed to reduce project risks and cost.
What is Test-Driven Development (TDD)?

TDD is a software development methodology involving repeatedly writing test cases for classes and then building the corresponding classes to implement only the code necessary to successful pass the tests.

For more terminology visit: http://www.headspringsystems.com/terminology.jsp
What is Domain-driven design(DDD)?

Domain-driven design (DDD) is an approach to the design of software, based on the two premises that complex domain designs should be based on a model, and that, for most software projects, the primary focus should be on the domain and domain logic (as opposed to being the particular technology used to implement the system).

For detail visit: http://en.wikipedia.org/wiki/Domain-driven_design
What is SRP?

SRP stands for Single Responsibility Principle. This states that a class should have only one reason to change. If a class is doing too much (i.e. hitting the DB, writing files, doing business logic, calling a web service, etc, it’s violating SRP. It will be very difficult to change later should we need to change it, and it will likely be prone to have more defects.

SRP applies to the methods or in a class also. The two are inseparable. A class, or object, is the combination of its data and its behavior.

For more details read this document: Single Responsibility Principle
http://www.objectmentor.com/resources/articles/srp.pdf

Source: With input from Chad Myers
The IHttpHandler and IHttpHandlerFactory interfaces ?

The IHttpHandler interface is implemented by all the handlers. The interface consists of one property called IsReusable. The IsReusable property gets a value indicating whether another request can use the IHttpHandler instance. The method ProcessRequest() allows you to process the current request. This is the core place where all your code goes. This method receives a parameter of type HttpContext using which you can access the intrinsic objects such as Request and Response. The IHttpHandlerFactory interface consists of two methods - GetHandler and ReleaseHandler. The GetHandler() method instantiates the required HTTP handler based on some condition and returns it back to ASP.NET. The ReleaseHandler() method allows the factory to reuse an existing handler.
What are design patterns

Design patterns are recurring solution to recurring problems in software architecture
What is Service Oriented architecture

SOA is a logical encapsulation of self contained business functionality. To know completely about SOA visit http://www.dotnetfunda.com/articles/article204.aspx on this website.

--------------------
Answer Edited:
How to avoid adding "Smart Tags" to your page when displayed by XP server ?

It can be achieved by a meta tag on the page the syntax is

<meta name="MSSmartTagsPreventParsing" content="TRUE">

How many design patterns are there and what are they?

According to Gang Of Four, there are three types of Design Pattern (Visit http://dofactory.com/Patterns/Patterns.aspx for more details)

1. Creational
2. Structural
3. Behavioral

Creational Design Pattern

Abstract Factory - Creates an instance of several families of classes
Builder - Separates object construction from its representation
Factory Method - Creates an instance of several derived classes
Prototype - A fully initialized instance to be copied or cloned
Singleton - A class of which only a single instance can exist

Structural Design Pattern

Adapter - Match interfaces of different classes
Bridge - Separates an object’s interface from its implementation
Composite - A tree structure of simple and composite objects
Decorator - Add responsibilities to objects dynamically
Facade - A single class that represents an entire subsystem
Flyweight - A fine-grained instance used for efficient sharing
Proxy - An object representing another object

Behavioral Design Pattern

Chain of Resp. - A way of passing a request between a chain of objects
Command - Encapsulate a command request as an object
Interpreter - A way to include language elements in a program
Iterator - Sequentially access the elements of a collection
Mediator - Defines simplified communication between classes
Memento - Capture and restore an object's internal state
Observer - A way of notifying change to a number of classes
State - Alter an object's behavior when its state changes
Strategy - Encapsulates an algorithm inside a class
Template Method - Defer the exact steps of an algorithm to a subclass
Visitor - Defines a new operation to a class without change

Above pattern and description has been copied from http://dofactory.com/Patterns/Patterns.aspx for information and knowledge purpose.
What is MVC Pattern?

MVC:

Model View Controller. MVC pattern seperates the GUI from the Data.
It is commonly used in ADO.NET programming in ASP.NET(example)

MVC in context with ADO.NET/ASP.NET

MVC pattern separates objects in to three important sections:-

Model: - This section is specially for maintaining data. It is actually where we write
code for database connectivity, methods of DataReader, DataAdapter, properties
for passing data and writing validations
eg: Business Access Layer class, Data Access Layer class.

View: - Design of the .aspx page (The markup or the presentation layer)

Controller: - They are event handling section which affects either the model or the view. (eg: .aspx.cs)
Difference between a Layer and Tier?


Layer:
It refers to the separation of the logic (i.e the code and design) that is developed for an application in different files.

Tier:
It refers to the physical location of the Layer files.

example:
In an ASP.NET web site, we create GUI web forms, business logic , data access
logic, database all in one computer. In this case, we have 4 layers and 1 Tier.
if the GUI Web Forms,business logic, data access logic and database are all in
different computers, we have 4 layers and 4 Tiers.
In what scenarios we should not use Design Patterns ?



We should not not use design patterns in following scenarios

• When the software is being designed and it would not change with time and new requirements.

• When the requirements of the source code of a particular application are unique and same.
Best naming conventions to initialize variables ?

Many new developers do not concentrate on prefixes of the variable declarations. But these initialization plays a major role because for large projects a single module will not be handled by a single individual so it must be generic that every one in the team should understand for what purpose a particular variable has been declared by just reading its name itself. So these are the generic steps to initialize variables.

------------------------------------------------------------------------------------------
Data Type---------------Example---------------Prefix
------------------------------------------------------------------------------------------
Boolean ------------------------ blnResult ------------------- bln
Byte ------------------------ bytYes ------------------- byt
Char ------------------------ chrSelect ------------------- chr
Date ------------------------ datStart ------------------- dat
Double ------------------------ dblSalary ------------------- dbl
Decimal ------------------------ decAverage ------------------- dec
Integer ------------------------ intStdid ------------------- int
Long ------------------------ lngValue ------------------- lng
Single ------------------------ sglStock ------------------- sql
Short ------------------------ shoShort ------------------- sho
String ------------------------ strEmpName ------------------- str
Object ------------------------ objSource ------------------- obj
What are all the three test cases that you should consider during unit testing?

The three test cases are :

1. Positive test cases - With this we need to provide correct data and test for correct output

2. Negative test cases - We need to check for broken or missing data

3. Exception test cases - Whether the exceptions which are thrown are handled properly or not
In Singleton Design Pattern, synchronization is essential ?

In Singleton Design Pattern , synchronization is essential only for the first time when the instance is to be created. When the instance is created then it becomes an overhead for each request.

public class Singleton

{
private static Singleton uniqueinstance;

private Singleton()
{
}

public static Singleton getinstance()
{
if(uniqueinstance == null)
{
uniqueinstance = new Singleton();
}
return uniqueinstance;
}
}


In the above code, when for the first time getinstance method is called, synchronization is needed. After the first instance is created, we no longer need synchronization.

Thanks and Regards
Akiii
In Singleton Pattern, how will you make sure that threading is done with minimal overhead ?

public sealed class Singleton

{
private static volatile Singleton instance;
private static object syncRoot = new Object();

private Singleton() {}

public static Singleton Instance
{
get
{
if (instance == null)
{
lock (syncRoot)
{
if (instance == null)
instance = new Singleton();
}
}

return instance;
}
}
}


In the above code, when the Singleton instance is created for the first time then it is locked and synchronized but next call or successive calls make sure that the lock is not checked anymore because an instance already exists. This way the overhead of checking the lock minimizes.

The double-check locking approach solves the thread concurrency problems while avoiding an exclusive lock in every call to the Instance property method.

Thanks and Regards
Akiii
How many design patterns can be created ?

There is no limit in creating a design pattern. Design patterns are based on re-usability, object creation and communication. Design patterns can be created in any language.

Thanks and Regards
Akiii
Why should a Singleton class be serialized only once ?

If a Singleton class is serialized and then De-serialized multiple times, there will be multiple objects which will violate the principles of Singleton pattern. Therefore it should be serialized and De-serialized only once !

Thanks and Regards
Akiii
Singleton is also called as Anti-Pattern, why ?

It's very hard to create a subclass, or to create a mock object for a Singleton class. Singleton makes the unit testing harder. Singleton hide the dependencies and make the classes tightly coupled with each other.

For the above reasons, Singletons are called as Anti-Pattern.


Thanks and Regards
Akiii
What is the importance of Design Pattern?

Here is a list of points which should be consider as some of the advantages of using design pattern

- It brings loose coupling
- It reduces object dependency
- It normalizes the communication between the client and the concrete classes.
- Simplifies the application handshaking
- Abstract the complex details from the client .
- Enhances Reusability
- Brings a fruitful framework
- Independent of language
- Components can be plugable
- Platform independent
- Can be applied in cross platform communication.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories