Earlier in Design Pattern : part 1, We have seen how we can use creational and structural design patterns. In this blog we will cover behaviour design patterns. This design patterns are equally important compare to earlier two and that's the reason it is asked frequently in java interview. The important design patterns are Visitor, Strategy, Command and Observer. Personally I have faced these questions in interview- How we can perform new operation in class without any change in class? Which design pattern is used for undo and redo in text formatter? How to notify object property change to a number of classes?
Chain of Responsibility:
This is a way of passing a request between a chain of objects. In this pattern there is a single chain of passing a request with many handlers. Each sender keeps a single reference to the head of the chain, and each receiver keeps a single reference to its immediate successor in the chain. This pattern is used to process those requests that are varied.
Command:
In this pattern we encapsulate a command request as an object. To call a method later we need some information like method name, its object and its values, to represent that information command pattern is used. It allows a request to be saved in a queue. The Command pattern has three main components: the Invoker, the Command, and the Receiver.
Interpreter:
This is a way to include language elements in a program. Interpreter pattern defines how the communication between the entities is controlled in a good manner and also defines the instructions grammar. The interpreter design pattern is useful for simple languages where performance is not critical.
Iterator :
It helps us sequentially access the elements of a collection. This pattern is used to provide the way to access the aggregate object without any knowledge of Aggregate structure. The iterator object will maintain the state of the iteration, keeping track of the current item and having a way of identifying what elements are next to be iterated. This allows traversing of lists, trees and other structures in a standard manner.
Mediator :
In this pattern we define simplified communication between classes. Mediator design pattern also deals with communication and defines an object to encapsulate that how the set of an object should interact. It promotes many-to-many relationships between interacting peers and thus defines simplifies communication between classes.
Memento :
In this pattern we capture and restore an object's internal state. This pattern proves to be helpful in saving the internal state of the object in to external state and enabling us to restore the state later when needed means it easily restore an object to its previous state with minimal lines of coding. Memento pattern helps us to store a snapshot which can be reverted at any moment of time by the object. A word processor providing undo operation or Ctrl+Z is the example of this pattern.
Observer :
In this we can find out a way of notifying change to a number of classes. This pattern allows us to plug objects into a framework at runtime, which allows for highly flexible, extensible, and reusable software. It is used when it is necessary to ensure that multiple components (called observers or subscribers) are kept in sync with a master set of data (the subject or publisher).
State:
State Pattern allows an object to alter its behavior dynamically according to its internal state. For this we directly move the logic to property "State" which has method Handle() and call this method.
Strategy:
It is useful when we want to encapsulates an algorithm inside a classes. The strategy pattern is very useful when we are in a need of a dynamic formula or data. It is used to separate different types of algorithms that serve a similar purpose. It's a strategy of dealing with a code design with a purpose to decouple concrete code into separate classes, which promotes reusability.
Template Method:
The main intention of this This pattern helps us to improve code reusability. It lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure. We cannot override the template method. Only the steps given in the skeleton of algorithm of template method need to be overridden in concrete classes.
Visitor :
With the help of visitor pattern the new operations are performed on an existing structure. The visitor pattern also specifies how iteration occurs over the object structure. It is a classic technique for recovering lost type information.
We are covering here -'Java
garbage collection interview questions' or 'Java memory
interview questions' in d...
|
Java util.collections is one of the most important package in java and the important of this package can be understand by...
|
Java Concurrency interview
question - In year 2004 when technology gurus said innovation
in Java is gone down and Sun Microsystems [Now Or...
|
'Java investment bank interview'
generally contains 'Java Design Pattern' questions. If you want
to be a professional Java ...
|
->Its really helpful for me to understand where we i lost in my previous interview. Thanks.
ReplyDeleteIf anyone wants to Learn Java in Chennai go to the Besant Technologies which is No.1 Training Institute in Chennai
This comment has been removed by the author.
ReplyDeleteTNPSC 813 Village Administrative Officer Recruitment 2015
ReplyDeleteWe need to thank admin for publishing useful information.........
I would like more information about this, because it is very nice., Thanks for sharing.
ReplyDeleteSignature:
i like play happy wheels demo online and play happy wheels games full and friv4school , games for girls , games go girls
The article gives me a lot of interesting information. I still often share life experiences with friends. And I enjoyed the convenience and attractiveness of free messaging app
ReplyDeletewhatsapp baixar , baixar whatsapp , baixar whatsapp gratis
vidyasthali is one of the best law college in India
ReplyDeleteVidyasthali Law College
Top Law Colleges in India
ReplyDeleteTop College Of law In Jaipur
ReplyDeletevidyasthali is one of the best law college in India
Vidyasthali Law College is a self-financing Institution affiliated to the University of Rajasthan
law college
law college in Jaipur
Best law college in Jaipur
Top College Of law In Jaipur
Vidyasthali Law College in jaipur
Vidyasthali Group of Institutions was founded by an eminent group of academics and industry leaders who are masters of the top significant achievements and accomplishments. Vidyasthali is a reputed B-school in Jaipur.
ReplyDeletevidyasthali institute of technology science&managment
vidyasthali institute of technology science and managment
vitsm
vitsm courses
top science college in jaipur.
Best science college in jaipur
Best science college in rajasthan
no 1 science college in jaipur
science & commerce college list,
best techonology science and management institute in jaipur
courses in vidyasthali group of institute
no 1 technology science & management college in jaipur
best management
Vidyasthali Law College is a self-financing Institution affiliated to the University of Rajasthan to impart qualitative instructions for the degree of LL.B. (Three-year) course.
ReplyDeletelaw college jaipur
llb college in jaipur
best law college in jaipur
law college rajasthan
rajasthan law college
colleges in jaipur for ba
ba llb colleges in jaipur
best law college in rajasthan
best law colleges in rajasthan
top law colleges in jaipur
private law colleges in jaipur
law colleges in jaipur rajasthan
5 year law colleges in jaipur
list of best college in jaipur
best law colleges
best law colleges in jaipur
best law colleges in india
colleges that do law
colleges that do law near me
law colleges for ba llb
law colleges for llb
law colleges best