Symantec Interview Question for Senior Software Development Engineers


Country: India




Comment hidden because of low score. Click to expand.
1
of 1 vote

Singleton is machnism that only one instance will exist in system.So, in order to achieve it, you should make your Construct and Copy Construct(also Operator =) private so one can not by them to create new object, finally give an interface:
ClassType * GetInstance(){
static ClassType *object = NULL;
if (NULL == object){
return new ClassType();
}
return object;
}
ps: think about inheritation, above code may have some problem.Also, in multi-thread enviroment, we should use double-lock to make sure only one instance will create by different thread.

- about Singleton April 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

it will always create new object, as object is set to NULL before checking

static ClassType *object = NULL; if (NULL == object)

- Anonymous April 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Factory and Singleton are the two most important ones as far as most interviews go. Those are the ones I've focused on.

- afarnoosh9 April 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think it'd be good if you could name the basic three categories (creational, structural, behavioral) and an example or two from each, and describe the difference between the categories as well while you're at it.

- Anonymous April 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class SingletonExample {
	
	/** Instance variable */
	private static SingletonExample m_objSingle = null;
	
	/**
	 * Private constructor. Not to access from other classes
	 */
	private SingletonExample() {}

	/**
	 * Method to return singleton object if the instance is null
	 * Otherwise return the same instance.
	 * synchronized block is used in case of multithreading
	 * @return {@link SingletonExample}
	 */
	public SingletonExample getInstance(){
		synchronized (m_objSingle) {
			if(null == m_objSingle) return new SingletonExample();
			else return m_objSingle;
		}
		
	}
}

- rizwan.amd April 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

some of the important creational design pattern that I know are:
Singleton
Factory method
Abstract factory
Prototype
Some of the important structural design patterns are
Adapter
Proxy
some of the important behavioral design patterns are
Observer
State
Command
Iterator
Strategy
template Method

Singleton : Only single instance of the class can be created. Make the constructor/destructor protected or private and make copy constructor and assignment operator private. Provide an static getInstance method that would allocate single object on heap if it hasn't already been allocated and return this single instance's pointer.

Factory method: This patterns relies on the derived class to create correct object for the target class. This pattern returns the product as an abstract product. For example to create a new product component the whole product class is derived and the new component's create method is overridden to return the new type of component. The final product is created by adding various components to it.

Abstract Factory: This pattern provides an interface for creating families of related object and returns objects as an abstract object so that the client code is not tightly coupled with the implementation of the interface.

Prototype: This pattern relies on the implementation of clone() method in each of the derived class. Clone operation is declared as pure virtual in the base class. Each derived class is responsible for cloning itself and returning the correct type of object through abstract base product interface.

Adapter: An old interface is adapted to the new interface that is required by the client application. For example if deque (STL class) need to be adapted to suit the stack abstraction then there is Stack (STL class) which works as an adapter which adapts queue to the need of application which requires stack abstraction.

Proxy: One object behaves as a proxy of another. Proxy object can implement resource hiding, security, smart manipulation of underlying object (smart pointer, shared pointer) etc.

Observer: One application (known as observer) registers with another application or library (Subject) dynamically by calling register or attach method on the subject. When ever there is an state change in the subject, subject->notify is called by the application which owns subject and inside notify each of the observer is updated (observer->update) is called for each registered observer object. List of observer can be maintained using any appropriate STL container class.

State : This pattern encapsulates the state machine mechanism for an object whos behavior on an event depends upon its current state. The class which needs to have state, contains a abstract instance of the state (pointer to state base class). When an event is to be handled by this class (class->handleEvent), then appropriate method is called on the state pointer (baseState->handleEvent1()). The base state is derived by concrete state and each concrete state implements only those operations which are valid in those states.

Command: command which implement execute or doit methods can be added dynamically to the objects which represents operations. These objects like a remote control represent a machinary having some functions and these functions have a dedicated object which represents that function. These objects are known as commands. The machinary (like remote control) contains all the commands in some associative control where a command object is mapped with a suitalbe enum (using stl maps).

Iteartor : Iterator provides a means for iterating through various objects hidden under a container, without depending upon the underlying implementation or representation of the container class. For example STL iterator classes which iterate through various sequence or associative containers like vector, list ,deque, map, multimap, set, multiset etc.

- Jitendra Singh September 26, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More