SlideShare a Scribd company logo
-To All Our Readers
Copyright ©            by

                                 All rights reserved.

                    Designed by




Copyright ©2012 Career Monk Publications. All rights reserved.

All rights reserved. No part of this book may be reproduced in any form or by any electronic
or mechanical means, including information storage and retrieval systems, without written
permission from the publisher or author.
Acknowledgements

First and foremost, we would like to thank our       , and dear           whose support
and encouragement throughout our lives have made it possible for us to build the skill set
necessary to succeed.

We would like to express our gratitude to many people who saw us through this book, to all
those who provided support, talked things over, read, wrote, offered comments, allowed us
to quote their remarks and assisted in the editing, proofreading and design. In particular, we
would like to thank the following individuals.

                               , Founder, Vegayan Systems Pvt. Ltd.
                     , Senior Manager, Microsoft India Pvt. Ltd.
                           , IIT Kanpur, Mentor Graphics Pvt. Ltd.
                              , IIT Kanpur, Microsoft India Pvt. Ltd.
                                   , Nokia Pvt. Ltd.
                      , IIT Bombay
                    , IIT Bombay, Google India Pvt. Ltd.
                             , IIT Bombay, De-Shaw India Pvt. Ltd.
                  , IIT Roorkee, Microsoft India Pvt. Ltd.
                                                 , Founder, StockMonks Pvt. Ltd.
                           , IIT Kharagpur, Xilinx Pvt. Ltd.
                           , Founders, Impression Design Studio Pvt. Ltd.


               -𝑃𝑟𝑜𝑓 𝑆𝑟𝑒𝑒𝑛𝑖𝑣𝑎𝑠𝑎 𝑅𝑎𝑜 𝑀𝑒𝑑𝑎                          -𝑁𝑎𝑟𝑎𝑠𝑖𝑚 𝑎 𝐾𝑎𝑟𝑢𝑚𝑎𝑛𝑐 𝑖
                Ph. D., Director, School of IT,                       M. Tech, 𝐼𝐼𝑇 𝐵𝑜𝑚𝑏𝑎𝑦
                            JNTU, Hyderabad                     Founder of 𝐶𝑎𝑟𝑒𝑒𝑟𝑀𝑜𝑛𝑘 𝑐𝑜𝑚
Peeling design patterns
Preface
Dear Reader,

Please Hold on! We know many people do not read preface. But we would like to strongly
recommend reading preface of this book at least. This preface has something       from
regular prefaces.

This book assumes you have basic knowledge about computer science. Main objective of the
book is     to provide you the           of design patterns and              questions.
Before writing the book, we set the following       :

       The book be written in                   that readers without any background in
        software design should be able to understand it        and            .
       The book should present the concepts of design patterns in                      and
        straightforward manner with a               explanation.
       After reading the book, they should be in a position to come up with        designs
        than before and participate in design discussions which happen in their       office
        work.
       The book should provide enough                  examples so that readers get better
        understanding of the design patterns and also useful for the interviews. We mean,
        the book should cover                     questions.
       After reading the book, the programmers should be in a position to try for software
        architect positions.

Design patterns were introduced to programming practices at the end of        as a result of
dissatisfaction with software’s state of affairs. In those days, few means of abstraction
(algorithms and data structures) suited well for procedural/functional programming. They
were       well connected with object-oriented programming.

The introduction of design patterns marks a turning point in the history of software design.
In       we have seen the publication of a catalogue (        ,      ,          &           ,
     ) with          -      design patterns written by four experienced object-oriented
designers. The catalogue, which came to be known as the                    (     ) catalogue,
was a super success.

Design patterns     novices (and             ) to avoid common                and encourage
experienced programmers to build better software.

This book is an enthusiastic celebration of design patterns, especially those which are given
by      . In the recept past, most of the object-oriented architectures are built with     of
design patterns.

In this book,    explained the design patterns with simple examples which helps
and              in understanding them easily. At the end of book, he gave common
                      which helps job seekers to perform better in their interviews.
A thorough understanding of the design patterns, processes, and methods in this book will
likewise help you develop better software applications and infrastructure. If you want
thorough coverage of the key patterns then read this book. We have learned much from it
and I am confident that you will too.

As a job seeker if you read complete book with good understanding, we are sure you will
challenge the interviewers and that is the objective of this book.

This book is very much useful for the students of engineering degree and masters during
their academic preparations. All the chapters of this book contain theory and their related
problems. If you read as a student preparing for competition exams, content of this book
covers all the required topics in full details.

It is                that, at least             reading of this book is required to get full
understanding of all the topics. In the              readings, you can directly go to any
chapter and refer. Even though, enough readings were given for correcting the errors, due to
human tendency there could be some minor typos in the book. If any such typos found, they
will be updated at www.               .com. We request you to constantly monitor this site
for any corrections, new problems and solutions. Also, please provide your valuable
suggestions at:                         .

                        Wish you all the best. Have a nice reading.

                 -𝑃𝑟𝑜𝑓 𝑆𝑟𝑒𝑒𝑛𝑖𝑣𝑎𝑠𝑎 𝑅𝑎𝑜 𝑀𝑒𝑑𝑎                     -𝑁𝑎𝑟𝑎𝑠𝑖𝑚 𝑎 𝐾𝑎𝑟𝑢𝑚𝑎𝑛𝑐 𝑖
                  Ph. D., Director, School of IT,                     M. Tech, 𝐼𝐼𝑇 𝐵𝑜𝑚𝑏𝑎𝑦
                              JNTU, Hyderabad               Founder of 𝐶𝑎𝑟𝑒𝑒𝑟𝑀𝑜𝑛𝑘 𝑐𝑜𝑚
Table of Contents

1. Introduction-------------------------------------------------------------- 11
  1.1 What Is This Book About? ----------------------------------------------------- 11
  1.2 Little History of Design Patterns ----------------------------------------------- 11
  1.3 Should I Take This Book? ------------------------------------------------------ 12
  1.4 Is It Useful For Interviews? ---------------------------------------------------- 12
  1.5 How To Use This book? -------------------------------------------------------- 12
  1.6 Organization Of Chapters ------------------------------------------------------ 13
  1.7 Source Code Disclaimer -------------------------------------------------------- 14
  1.8 Tools Used For Book ----------------------------------------------------------- 14
2. UML Basics --------------------------------------------------------------- 15
  2.1 What Is UML? ------------------------------------------------------------------ 15
  2.2 Why UML? --------------------------------------------------------------------- 15
  2.3 UML Notations ----------------------------------------------------------------- 15
  2.4 Object Oriented Concepts ------------------------------------------------------ 16
  2.5 OO Analysis and Design (OOAD) --------------------------------------------- 18
  2.6 UML Building Blocks and Notations ------------------------------------------- 19
  2.7 Things--------------------------------------------------------------------------- 19
  2.8 Relationship -------------------------------------------------------------------- 25
  2.9 UML Diagrams ----------------------------------------------------------------- 29
3. Design Patterns Introduction -------------------------------------------- 38
  3.1 What are Design Patterns? ----------------------------------------------------- 38
  3.2 Little History of Design Patterns ----------------------------------------------- 38
  3.3 Why Design Patterns?---------------------------------------------------------- 38
  3.4 Categories Of Design Patterns ------------------------------------------------- 39
  3.5 What To Observe For A Design Pattern? -------------------------------------- 40
  3.6 Using Patterns To Gain Experience -------------------------------------------- 40
3.7 Can We Use Design Patterns Always? ------------------------------------------ 41
  3.8 Design Patterns vs. Frameworks ------------------------------------------------ 41
4. Creational Patterns ------------------------------------------------------ 43
  4.1 Creational Design Patterns ------------------------------------------------------ 43
  4.2 Categories Of Creational Design Patterns -------------------------------------- 43
  4.3 Factory Method Design Pattern ------------------------------------------------ 44
  4.4 Abstract Factory Design Pattern ------------------------------------------------ 48
  4.5 Builder Design Pattern ---------------------------------------------------------- 52
  4.6 Singleton Design Pattern -------------------------------------------------------- 60
  4.7 Prototype Design Pattern ------------------------------------------------------- 65
5. Structural Patterns ------------------------------------------------------- 70
  5.1 Structural Design Patterns ------------------------------------------------------ 70
  5.2 Categories Of Structural Design Patterns --------------------------------------- 70
  5.3 Adapter Design Pattern --------------------------------------------------------- 71
  5.4 Bridge Design Pattern ----------------------------------------------------------- 77
  5.5 Composite Design Pattern ------------------------------------------------------ 80
  5.6 Decorator Design Pattern ------------------------------------------------------- 86
  5.7 Facade Design Pattern----------------------------------------------------------- 93
  5.8 Proxy Design Pattern ----------------------------------------------------------- 99
  5.9 Flyweight pattern ------------------------------------------------------------- 102
6. Behavioral Patterns ----------------------------------------------------- 109
  6.1 Behavioral Design Patterns --------------------------------------------------- 109
  6.2 Categories Of Behavioral Design Patterns ------------------------------------ 109
  6.3 Chain Of Responsibility Design Pattern -------------------------------------- 110
  6.4 Command Design Pattern ----------------------------------------------------- 116
  6.5 Interpreter Design Pattern ---------------------------------------------------- 121
  6.6 Iterator Design Pattern -------------------------------------------------------- 125
  6.7 Mediator Design Pattern ------------------------------------------------------ 132
  6.8 Memento Design Pattern ----------------------------------------------------- 138
  6.9 Observer Design Pattern ------------------------------------------------------ 142
  6.10 State Design Pattern --------------------------------------------------------- 147
6.11 Strategy Design Pattern ------------------------------------------------------ 150
  6.12 Template Method Design Pattern ------------------------------------------- 153
  6.13 Visitor Design Pattern ------------------------------------------------------- 156
7. Glossary and Tips ------------------------------------------------------- 161
  7.1 What Are Design Patterns? --------------------------------------------------- 161
  7.2 How To Use Design Patterns?------------------------------------------------- 161
  7.3 Why Design Patterns?--------------------------------------------------------- 162
  7.4 What To Observe For A Design Pattern? ------------------------------------- 162
  7.5 Using Patterns To Gain Experience ------------------------------------------- 162
  7.6 How To Choose A Design Pattern? ------------------------------------------- 163
  7.7 Can We Use Design Patterns Always? ---------------------------------------- 163
  7.8 Categories Of Design Patterns ------------------------------------------------ 164
  7.9 Creational Design Patterns ---------------------------------------------------- 164
  7.10 Structural Design Patterns --------------------------------------------------- 165
  7.11 Behavioral Design Patterns -------------------------------------------------- 166
  7.12 What Are Antipatterns? ----------------------------------------------------- 167
  7.13 Refactoring ------------------------------------------------------------------- 168
  7.14 Design Patterns vs. Frameworks --------------------------------------------- 168
  7.15 Tips --------------------------------------------------------------------------- 168
8. Design Interview Questions -------------------------------------------- 171
  8.1 Design Interview Questions--------------------------------------------------- 171
  8.2 Sample Design Questions For Practice---------------------------------------- 250
9. Miscellaneous Concepts ------------------------------------------------- 252
  9.1 Java Interview Questions------------------------------------------------------ 252
PEELING DESIGN PATTERNS
        (FOR BEGINNERS AND INTERVIEWS)

Other Titles by 𝑁𝑎𝑟𝑎𝑠𝑖𝑚 𝑎 𝐾𝑎𝑟𝑢𝑚𝑎𝑛𝑐 𝑖
        Success keys for Big Job Hunters

  Data Structures and Algorithms Made Easy (C/C++)

  Data Structures and Algorithms Made Easy in Java
  Data Structures and Algorithms for GATE
  Coding Interview Questions

More Related Content

PDF
It interview questions
PDF
Peeling Design Patterns
PDF
Data structures and algorithms made easy
PDF
Data structures and algorithms made easy java
PDF
Data Structures and Algorithms made Easy (Cover Page)
PDF
Data Structures and Algorithms For GATE: Solutions to all previous GATE quest...
PDF
Sample chapters [data structure and algorithmic thinking with python]
PDF
Table of contents [data structure and algorithmic thinking with python]
It interview questions
Peeling Design Patterns
Data structures and algorithms made easy
Data structures and algorithms made easy java
Data Structures and Algorithms made Easy (Cover Page)
Data Structures and Algorithms For GATE: Solutions to all previous GATE quest...
Sample chapters [data structure and algorithmic thinking with python]
Table of contents [data structure and algorithmic thinking with python]

Similar to Peeling design patterns (20)

PDF
Professional Microsoft Smartphone Programming 1st Edition Baijian Yang
DOCX
Design pattern application
PDF
Datastructuresandalgorithms
PDF
Simple Object Oriented Design (MEAP V04) Mauricio Aniche
PDF
Patterns of enterprise application architecture
PDF
5b9b046 sample interviewquestionbook(1)
PDF
5b9b046 sample interviewquestionbook(1)
PDF
046 sample interviewquestionbook(1)
PDF
046 sample interviewquestionbook(1)
PDF
Largescale Software Architecture A Practical Guide Using Uml 1st Edition Garland
PDF
Software engineering marsic
PDF
Mta ssg soft_dev_individual_without_crop
PDF
SADP PPTs of all modules - Shanthi D.L.pdf
PDF
130607 yann-gael gueheneuc - ptidej tool suite
PDF
Industrial trainingsoftware 2011
PDF
Best Software Training Institute in Hyderabad
PDF
Java Data Access Jdbc Jndi And Jaxp Thomas Tm
PDF
Data structure and algorithmic thinking with python cover
PDF
Essential java script design patterns
Professional Microsoft Smartphone Programming 1st Edition Baijian Yang
Design pattern application
Datastructuresandalgorithms
Simple Object Oriented Design (MEAP V04) Mauricio Aniche
Patterns of enterprise application architecture
5b9b046 sample interviewquestionbook(1)
5b9b046 sample interviewquestionbook(1)
046 sample interviewquestionbook(1)
046 sample interviewquestionbook(1)
Largescale Software Architecture A Practical Guide Using Uml 1st Edition Garland
Software engineering marsic
Mta ssg soft_dev_individual_without_crop
SADP PPTs of all modules - Shanthi D.L.pdf
130607 yann-gael gueheneuc - ptidej tool suite
Industrial trainingsoftware 2011
Best Software Training Institute in Hyderabad
Java Data Access Jdbc Jndi And Jaxp Thomas Tm
Data structure and algorithmic thinking with python cover
Essential java script design patterns
Ad

Recently uploaded (20)

PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Cell Structure & Organelles in detailed.
PDF
Classroom Observation Tools for Teachers
PPTX
Presentation on HIE in infants and its manifestations
PPTX
Pharma ospi slides which help in ospi learning
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
RMMM.pdf make it easy to upload and study
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Institutional Correction lecture only . . .
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Anesthesia in Laparoscopic Surgery in India
STATICS OF THE RIGID BODIES Hibbelers.pdf
Microbial diseases, their pathogenesis and prophylaxis
Cell Structure & Organelles in detailed.
Classroom Observation Tools for Teachers
Presentation on HIE in infants and its manifestations
Pharma ospi slides which help in ospi learning
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Supply Chain Operations Speaking Notes -ICLT Program
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
VCE English Exam - Section C Student Revision Booklet
human mycosis Human fungal infections are called human mycosis..pptx
RMMM.pdf make it easy to upload and study
GDM (1) (1).pptx small presentation for students
Module 4: Burden of Disease Tutorial Slides S2 2025
Computing-Curriculum for Schools in Ghana
Institutional Correction lecture only . . .
O7-L3 Supply Chain Operations - ICLT Program
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Ad

Peeling design patterns

  • 1. -To All Our Readers
  • 2. Copyright © by All rights reserved. Designed by Copyright ©2012 Career Monk Publications. All rights reserved. All rights reserved. No part of this book may be reproduced in any form or by any electronic or mechanical means, including information storage and retrieval systems, without written permission from the publisher or author.
  • 3. Acknowledgements First and foremost, we would like to thank our , and dear whose support and encouragement throughout our lives have made it possible for us to build the skill set necessary to succeed. We would like to express our gratitude to many people who saw us through this book, to all those who provided support, talked things over, read, wrote, offered comments, allowed us to quote their remarks and assisted in the editing, proofreading and design. In particular, we would like to thank the following individuals.  , Founder, Vegayan Systems Pvt. Ltd.  , Senior Manager, Microsoft India Pvt. Ltd.  , IIT Kanpur, Mentor Graphics Pvt. Ltd.  , IIT Kanpur, Microsoft India Pvt. Ltd.  , Nokia Pvt. Ltd.  , IIT Bombay  , IIT Bombay, Google India Pvt. Ltd.  , IIT Bombay, De-Shaw India Pvt. Ltd.  , IIT Roorkee, Microsoft India Pvt. Ltd.  , Founder, StockMonks Pvt. Ltd.  , IIT Kharagpur, Xilinx Pvt. Ltd.  , Founders, Impression Design Studio Pvt. Ltd. -𝑃𝑟𝑜𝑓 𝑆𝑟𝑒𝑒𝑛𝑖𝑣𝑎𝑠𝑎 𝑅𝑎𝑜 𝑀𝑒𝑑𝑎 -𝑁𝑎𝑟𝑎𝑠𝑖𝑚 𝑎 𝐾𝑎𝑟𝑢𝑚𝑎𝑛𝑐 𝑖 Ph. D., Director, School of IT, M. Tech, 𝐼𝐼𝑇 𝐵𝑜𝑚𝑏𝑎𝑦 JNTU, Hyderabad Founder of 𝐶𝑎𝑟𝑒𝑒𝑟𝑀𝑜𝑛𝑘 𝑐𝑜𝑚
  • 5. Preface Dear Reader, Please Hold on! We know many people do not read preface. But we would like to strongly recommend reading preface of this book at least. This preface has something from regular prefaces. This book assumes you have basic knowledge about computer science. Main objective of the book is to provide you the of design patterns and questions. Before writing the book, we set the following :  The book be written in that readers without any background in software design should be able to understand it and .  The book should present the concepts of design patterns in and straightforward manner with a explanation.  After reading the book, they should be in a position to come up with designs than before and participate in design discussions which happen in their office work.  The book should provide enough examples so that readers get better understanding of the design patterns and also useful for the interviews. We mean, the book should cover questions.  After reading the book, the programmers should be in a position to try for software architect positions. Design patterns were introduced to programming practices at the end of as a result of dissatisfaction with software’s state of affairs. In those days, few means of abstraction (algorithms and data structures) suited well for procedural/functional programming. They were well connected with object-oriented programming. The introduction of design patterns marks a turning point in the history of software design. In we have seen the publication of a catalogue ( , , & , ) with - design patterns written by four experienced object-oriented designers. The catalogue, which came to be known as the ( ) catalogue, was a super success. Design patterns novices (and ) to avoid common and encourage experienced programmers to build better software. This book is an enthusiastic celebration of design patterns, especially those which are given by . In the recept past, most of the object-oriented architectures are built with of design patterns. In this book, explained the design patterns with simple examples which helps and in understanding them easily. At the end of book, he gave common which helps job seekers to perform better in their interviews.
  • 6. A thorough understanding of the design patterns, processes, and methods in this book will likewise help you develop better software applications and infrastructure. If you want thorough coverage of the key patterns then read this book. We have learned much from it and I am confident that you will too. As a job seeker if you read complete book with good understanding, we are sure you will challenge the interviewers and that is the objective of this book. This book is very much useful for the students of engineering degree and masters during their academic preparations. All the chapters of this book contain theory and their related problems. If you read as a student preparing for competition exams, content of this book covers all the required topics in full details. It is that, at least reading of this book is required to get full understanding of all the topics. In the readings, you can directly go to any chapter and refer. Even though, enough readings were given for correcting the errors, due to human tendency there could be some minor typos in the book. If any such typos found, they will be updated at www. .com. We request you to constantly monitor this site for any corrections, new problems and solutions. Also, please provide your valuable suggestions at: . Wish you all the best. Have a nice reading. -𝑃𝑟𝑜𝑓 𝑆𝑟𝑒𝑒𝑛𝑖𝑣𝑎𝑠𝑎 𝑅𝑎𝑜 𝑀𝑒𝑑𝑎 -𝑁𝑎𝑟𝑎𝑠𝑖𝑚 𝑎 𝐾𝑎𝑟𝑢𝑚𝑎𝑛𝑐 𝑖 Ph. D., Director, School of IT, M. Tech, 𝐼𝐼𝑇 𝐵𝑜𝑚𝑏𝑎𝑦 JNTU, Hyderabad Founder of 𝐶𝑎𝑟𝑒𝑒𝑟𝑀𝑜𝑛𝑘 𝑐𝑜𝑚
  • 7. Table of Contents 1. Introduction-------------------------------------------------------------- 11 1.1 What Is This Book About? ----------------------------------------------------- 11 1.2 Little History of Design Patterns ----------------------------------------------- 11 1.3 Should I Take This Book? ------------------------------------------------------ 12 1.4 Is It Useful For Interviews? ---------------------------------------------------- 12 1.5 How To Use This book? -------------------------------------------------------- 12 1.6 Organization Of Chapters ------------------------------------------------------ 13 1.7 Source Code Disclaimer -------------------------------------------------------- 14 1.8 Tools Used For Book ----------------------------------------------------------- 14 2. UML Basics --------------------------------------------------------------- 15 2.1 What Is UML? ------------------------------------------------------------------ 15 2.2 Why UML? --------------------------------------------------------------------- 15 2.3 UML Notations ----------------------------------------------------------------- 15 2.4 Object Oriented Concepts ------------------------------------------------------ 16 2.5 OO Analysis and Design (OOAD) --------------------------------------------- 18 2.6 UML Building Blocks and Notations ------------------------------------------- 19 2.7 Things--------------------------------------------------------------------------- 19 2.8 Relationship -------------------------------------------------------------------- 25 2.9 UML Diagrams ----------------------------------------------------------------- 29 3. Design Patterns Introduction -------------------------------------------- 38 3.1 What are Design Patterns? ----------------------------------------------------- 38 3.2 Little History of Design Patterns ----------------------------------------------- 38 3.3 Why Design Patterns?---------------------------------------------------------- 38 3.4 Categories Of Design Patterns ------------------------------------------------- 39 3.5 What To Observe For A Design Pattern? -------------------------------------- 40 3.6 Using Patterns To Gain Experience -------------------------------------------- 40
  • 8. 3.7 Can We Use Design Patterns Always? ------------------------------------------ 41 3.8 Design Patterns vs. Frameworks ------------------------------------------------ 41 4. Creational Patterns ------------------------------------------------------ 43 4.1 Creational Design Patterns ------------------------------------------------------ 43 4.2 Categories Of Creational Design Patterns -------------------------------------- 43 4.3 Factory Method Design Pattern ------------------------------------------------ 44 4.4 Abstract Factory Design Pattern ------------------------------------------------ 48 4.5 Builder Design Pattern ---------------------------------------------------------- 52 4.6 Singleton Design Pattern -------------------------------------------------------- 60 4.7 Prototype Design Pattern ------------------------------------------------------- 65 5. Structural Patterns ------------------------------------------------------- 70 5.1 Structural Design Patterns ------------------------------------------------------ 70 5.2 Categories Of Structural Design Patterns --------------------------------------- 70 5.3 Adapter Design Pattern --------------------------------------------------------- 71 5.4 Bridge Design Pattern ----------------------------------------------------------- 77 5.5 Composite Design Pattern ------------------------------------------------------ 80 5.6 Decorator Design Pattern ------------------------------------------------------- 86 5.7 Facade Design Pattern----------------------------------------------------------- 93 5.8 Proxy Design Pattern ----------------------------------------------------------- 99 5.9 Flyweight pattern ------------------------------------------------------------- 102 6. Behavioral Patterns ----------------------------------------------------- 109 6.1 Behavioral Design Patterns --------------------------------------------------- 109 6.2 Categories Of Behavioral Design Patterns ------------------------------------ 109 6.3 Chain Of Responsibility Design Pattern -------------------------------------- 110 6.4 Command Design Pattern ----------------------------------------------------- 116 6.5 Interpreter Design Pattern ---------------------------------------------------- 121 6.6 Iterator Design Pattern -------------------------------------------------------- 125 6.7 Mediator Design Pattern ------------------------------------------------------ 132 6.8 Memento Design Pattern ----------------------------------------------------- 138 6.9 Observer Design Pattern ------------------------------------------------------ 142 6.10 State Design Pattern --------------------------------------------------------- 147
  • 9. 6.11 Strategy Design Pattern ------------------------------------------------------ 150 6.12 Template Method Design Pattern ------------------------------------------- 153 6.13 Visitor Design Pattern ------------------------------------------------------- 156 7. Glossary and Tips ------------------------------------------------------- 161 7.1 What Are Design Patterns? --------------------------------------------------- 161 7.2 How To Use Design Patterns?------------------------------------------------- 161 7.3 Why Design Patterns?--------------------------------------------------------- 162 7.4 What To Observe For A Design Pattern? ------------------------------------- 162 7.5 Using Patterns To Gain Experience ------------------------------------------- 162 7.6 How To Choose A Design Pattern? ------------------------------------------- 163 7.7 Can We Use Design Patterns Always? ---------------------------------------- 163 7.8 Categories Of Design Patterns ------------------------------------------------ 164 7.9 Creational Design Patterns ---------------------------------------------------- 164 7.10 Structural Design Patterns --------------------------------------------------- 165 7.11 Behavioral Design Patterns -------------------------------------------------- 166 7.12 What Are Antipatterns? ----------------------------------------------------- 167 7.13 Refactoring ------------------------------------------------------------------- 168 7.14 Design Patterns vs. Frameworks --------------------------------------------- 168 7.15 Tips --------------------------------------------------------------------------- 168 8. Design Interview Questions -------------------------------------------- 171 8.1 Design Interview Questions--------------------------------------------------- 171 8.2 Sample Design Questions For Practice---------------------------------------- 250 9. Miscellaneous Concepts ------------------------------------------------- 252 9.1 Java Interview Questions------------------------------------------------------ 252
  • 10. PEELING DESIGN PATTERNS (FOR BEGINNERS AND INTERVIEWS) Other Titles by 𝑁𝑎𝑟𝑎𝑠𝑖𝑚 𝑎 𝐾𝑎𝑟𝑢𝑚𝑎𝑛𝑐 𝑖 Success keys for Big Job Hunters Data Structures and Algorithms Made Easy (C/C++) Data Structures and Algorithms Made Easy in Java Data Structures and Algorithms for GATE Coding Interview Questions