The largest Interview Solution Library on the web


Interview Questions
« Previous | 0 | 1 | 2 | 3 | 4 | Next »

21.What is Decorator pattern?

  • Decorator pattern allows a user to add new functionality to an existing object without altering its structure.

  • This type of design pattern comes under structural pattern as this pattern acts as a wrapper to existing class.

  • This pattern creates a decorator class which wraps the original class and provides additional functionality keeping class methods signature intact.

22.What is Facade pattern?

  • Facade pattern hides the complexities of the system and provides an interface to the client using which the client can access the system.

  • This type of design pattern comes under structural pattern as this pattern adds an interface to existing system to hide its complexities.

  • This pattern involves a single class which provides simplified methods required by client and delegates calls to methods of existing system classes.

23.What is Flyweight pattern?

  • Flyweight pattern is primarily used to reduce the number of objects created and to decrease memory footprint and increase performance.

  • This type of design pattern comes under structural pattern as this pattern provides ways to decrease object count thus improving the object structure of application.

  • Flyweight pattern tries to reuse already existing similar kind objects by storing them and creates new object when no matching object is found.

24.What is Proxy pattern?

  • In proxy pattern, a class represents functionality of another class.

  • This type of design pattern comes under structural pattern.

  • In proxy pattern, we create object having original object to interface its functionality to outer world.

25.What is Chain of Responsibility pattern?

  • As the name suggests, the chain of responsibility pattern creates a chain of receiver objects for arequest.

  • This pattern decouples sender and receiver of a request based on type of request.

  • Thispattern comes under behavioral patterns.

  • In this pattern, normally each receiver contains reference to another receiver.

  • If one object cannot handle the request then it passes the same to the next receiver and so on.

26.What is Command pattern?

  • Command pattern is a data driven design pattern and falls under behavioral pattern category.

  • A request is wrapped under an object as command and passed to invoker object.

  • Invoker object looks for the appropriate object which can handle this command and passes the command to the corresponding object which executes the command.

27.What is Interpreter pattern?

  • Interpreter pattern provides a way to evaluate language grammar or expression.

  • This type of pattern comes under behavioral pattern.

  • This pattern involves implementing an expression interface which tells to interpret a particular context.

28.Give an example where Interpreter pattern is used?

  • This pattern is used in SQL parsing, symbol processing engine etc.

29.What is Iterator pattern?

  • Iterator pattern is very commonly used design pattern in Java and.

  • Net programming environment.

  • This pattern is used to get a way to access the elements of a collection object in sequential manner without any need to know its underlying representation.

  • Iterator pattern falls under behavioral pattern category.

30.What are the entities of Service Locator pattern?

Following are the entities of this type of design pattern.

  • Service - Actual Service which will process the request. Reference of such service is to be looked upon in JNDI server.

  • Context / Initial Context - JNDI Context carries the reference to service used for lookup purpose.

  • Service Locator - Service Locator is a single point of contact to get services by JNDI lookup caching the services.

  • Cache - Cache to store references of services to reuse them.

  • Client - Client is the object that invokes the services via ServiceLocator.

31.What is Mediator pattern?

  • Mediator pattern is used to reduce communication complexity between multiple objects or classes.

  • This pattern provides a mediator class which normally handles all the communications between different classes and supports easy maintenance of the code by loose coupling.

  • Mediator pattern falls under behavioral pattern category.

32.What is Memento pattern?

  • Memento pattern is used to restore state of an object to a previous state.

  • Memento pattern falls under behavioral pattern category.

33.Name the actor classes used in Memento pattern?

  • Memento pattern uses three actor classes.

  • Memento contains state of an object to be restored.

  • Originator creates and stores states in Memento objects and Caretaker object is responsible to restore object state from Memento.

34.What is Observer pattern?

  • Observer pattern is used when there is one-to-many relationship between objects such as if one object is modified, its depenedent objects are to be notified automatically.

  • Observer pattern falls under behavioral pattern category.

35.Name the actor classes used in Observer pattern?

  • Observer pattern uses three actor classes. Subject, Observer and Client.

  • Subject is an object having methods to attach and detach observers to a client object.

  • We have created an abstract class Observer and a concrete class Subject that is extending class Observer.

36.What is state pattern?

  • In State pattern a class behavior changes based on its state.

  • This type of design pattern comes under behavior pattern.

  • In State pattern, we create objects which represent various states and a context object whose behavior varies as its state object changes.

37.What is Null Object pattern?

  • In Null Object pattern, a null object replaces check of NULL object instance.

  • Instead of putting if check for a null value, Null Object reflects a do nothing relationship.

  • Such Null object can also be used to provide default behaviour in case data is not available.

  • In Null Object pattern, we create an abstract class specifying various operations to be done, concrete classes extending this class and a null object class providing do nothing implemention of this class and will be used seemlessly where we need to check null value.

38.What is Strategy pattern?

  • In Strategy pattern, a class behavior or its algorithm can be changed at run time.

  • This type of design pattern comes under behavior pattern.

  • In Strategy pattern, we create objects which represent various strategies and a context object whose behavior varies as per its strategy object.

  • The strategy object changes the executing algorithm of the context object.

39.What is Template pattern?

  • In Template pattern, an abstract class exposes defined ways/templates to execute its methods.

  • Its subclasses can override the method implementation as per need but the invocation is to be in the same way as defined by an abstract class.

  • This pattern comes under behavior pattern category.

40.What is Visitor pattern?

  • In Visitor pattern, we use a visitor class which changes the executing algorithm of an element class.

  • By this way, execution algorithm of element can vary as and when visitor varies.

  • This pattern comes under behavior pattern category.

  • As per the pattern, element object has to accept the visitor object so that visitor object handles the operation on the element object.

« Previous | 0 | 1 | 2 | 3 | 4 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com