[转]Design Pattern Interview Questions - Part 2
- (I) what is Interpreter pattern?
- (B) Can you explain iterator pattern?
- (A) Can you explain mediator pattern?
- (I) Can you explain memento pattern?
- (B) Can you explain observer pattern?
Other Interview question PDF's
Introduction
Again i repeat do not think you get an architecture position by reading interview questions. But yes there should be some kind of reference which will help you quickly revise what are the definition. Just by reading these answers you get to a position where you are aware of the fundamentals. But if you have not really worked you will surely fail with scenario based questions. So use this as a quick revision rather than a shot cut.
In case your are completely new to design patterns or you really do not want to read this complete article do see our free design pattern Training and interview questions / answers videos.
If you have not read my pervious section you can always read from below
- Part 1 Design pattern interview questions http://www.dotnetfunda.com/articles/article130.aspx
- Part 3 Design Pattern Interview Questions :- http://www.dotnetfunda.com/articles/article137.aspx
- Part 4 Design pattern Interview Questions :- http://www.dotnetfunda.com/articles/article139.aspx
Happy job hunting......
(I) what is Interpreter pattern?
Figure: - Grammar mapped to classes
Figure :- Class diagram for interpreter
Figure: - Expression and Context classes
Figure: - Client Interpreter logic
Note :- You can find the code for interpreter in ‘Interpeter’ folder.
(B) Can you explain iterator pattern?
Iterator pattern allows sequential access of elements with out exposing the inside code. Let’s understand what it means. Let’s say you have a collection of records which you want to browse sequentially and also maintain the current place which recordset is browsed, then the answer is iterator pattern. It’s the most common and unknowingly used pattern. Whenever you use a ‘foreach’ (It allows us to loop through a collection sequentially) loop you are already using iterator pattern to some extent.
Figure: - Iterator business logic
In figure ‘Iterator business logic’ we have the ‘clsIterator’ class which has collection of customer classes. So we have defined an array list inside the ‘clsIterator’ class and a ‘FillObjects’ method which loads the array list with data. The customer collection array list is private and customer data can be looked up by using the index of the array list. So we have public function like ‘getByIndex’ ( which can look up using a particular index) , ‘Prev’ ( Gets the previous customer in the collection , ‘Next’ (Gets the next customer in the collection), ‘getFirst’ ( Gets the first customer in the collection ) and ‘getLast’ ( Gets the last customer in the collection).
So the client is exposed only these functions. These functions take care of accessing the collection sequentially and also it remembers which index is accessed.
Below figures ‘Client Iterator Logic’ shows how the ‘ObjIterator’ object which is created from class ‘clsIterator’ is used to display next, previous, last, first and customer by index.
Figure: - Client Iterator logic
Note :- You can get a sample C# code in the ‘Iterator’ folder of the CD provided with this book.
(A) Can you explain mediator pattern?
Figure: - Mediator sample example
Figure: - Complex interactions between components
Figure: - Simplifying using mediator
Figure: - Mediator class
The client logic is pretty neat and cool now. In the constructor we first register all the components with complex interactions with the mediator. Now for every scenario we just call the mediator methods. In short when there is a text change we can the ‘TextChange’ method of the mediator, when the user clicks add we call the ‘ClickAddButton’ and for clear click we call the ‘ClickClearButton’.
Figure: - Mediator client logic
Note :- You can get the C# code for the above mediator example in the ‘mediator’ folder.
(I) Can you explain memento pattern?
Figure: - Memento practical example
Figure: - Customer class for memento
Note :- A sample code in C# for memento is available in the memento folder of the CD.
(B) Can you explain observer pattern?
Figure: - Subject and Observers
Figure: - Publisher/Subject classes
Figure: - Observer client code
Note :- You can get the C# code snippet for observer pattern from the CD in ‘Observer’ folder.
转载于:https://www.cnblogs.com/yfdream/p/3511193.html
[转]Design Pattern Interview Questions - Part 2相关推荐
- C# Interview Questions and Answers
What's C# ?C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived f ...
- 机器学习面试题合集Collection of Machine Learning Interview Questions
The Machine Learning part of the interview is usually the most elaborate one. That's the reason we h ...
- Java developer interview questions: The hard part
Since I've attended several job interviews recently, I've decided toshare some experience with you. ...
- 面试时最经常被问到的问题(Frenquently asked interview questions)(II)
面试时最经常被问到的问题(Frenquently asked interview questions)(II) 面试时最经常被问到的问题(Frenquently asked interview que ...
- 论文《Evaluating the impact of design pattern and anti-pattern dependencies on changes》笔记
Evaluating the impact of design pattern and anti-pattern dependencies on changes and faults 评估设计模式和反 ...
- (原創) 我的Design Pattern之旅[3]:使用template改進Strategy Pattern (OO) (Design Pattern) (C/C++) (template)...
在strategy pattern中,為了讓各strategy能方便存取原來物件的所有public member function,我們常用*this將整個物件傳給各strategy,這樣的設計並沒有 ...
- 5 Best User Interface Design Pattern Libraries
为什么80%的码农都做不了架构师?>>> Elements of Design Pattern Tap Patternry UI Patterns http://uxmovem ...
- 说说设计模式~大话目录(Design Pattern)
回到占占推荐博客索引 设计模式(Design pattern)与其它知识不同,它没有华丽的外表,没有吸引人的工具去实现,它是一种心法,一种内功,如果你希望在软件开发领域有一种新的突破,一个质的飞越,那 ...
- Design Pattern Template Method C
分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! Defi ...
最新文章
- 广东移动节能绿色数据中心掀起“能耗革命”
- 后端系统开发之白名单机制
- git只提交一张图片_Git 图形化操作之合并提交记录
- leetcode 33 搜索旋转排序数组 到处是细节的好题
- php控制器实现自动映射,PHP实现路由映射到指定控制器
- html简单跨行跨列表格制作
- 手势识别器GestureDetector
- IPv6带给互联网的新契机
- oracle数据库学习相关笔记-相关约束
- 个人对游戏加速器行业看法(二):加速器现有架构梳理
- G711音频文件播放器
- 友华PT925E,电信天翼网关3.0,光猫超级密码获取最简便方式
- python保存图片到本地代码_python保存网页图片到本地的方法
- 软件测试周刊(第63期):凡是持久的,必是温和的与可持续的。
- 如何在 6 月 7 日观看 Apple 的 WWDC 2021 主题演讲
- 优化性能问题的一般方法
- JS gkb转utf8(fetch gbk网页是乱码)
- 【Python】Scrapy完成电影信息爬取并存入数据库
- 谷粒商城-03-p28-p44
- 《计算机视觉》期末考试复习资料