如何回答面试问题:什么是单身,你会如何使用呢? [英] How to answer the interview question: What is a singleton and how would you use one?

查看:214
本文介绍了如何回答面试问题:什么是单身,你会如何使用呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过关于S.O.问题对于单身和刚看了一个小时的谷歌技术讲座。据我所知,于二OO世界的共识似乎是,单身人士更反模式,而不是一个有用的设计模式。

I've read the questions on S.O. regarding Singleton and just watched an hour long google tech talk. As far as I can tell, the consensus in the OO world seems to be that singletons are more of an anti-pattern rather than a useful design pattern.

这是说,我采访的这些天,问题来了很多 - 什么是单身,你会如何使用它

That said, I am interviewing these days and the question comes up a lot--what is a singleton, and how would you use it?

什么是回答这个问题的最佳方式是什么?我应该简单介绍一下这个设计模式,然后说是唯一可接受的使用我听说的是记录,而这往往是误用全局状态?​​

What is the best way to answer this question? Should I simply describe the design pattern and then say the only acceptable use I've heard of is for logging, and that it is often mis-used for global state?

推荐答案

整蛊。有很多的人谁觉得单身本质上是一种反模式,就像你说的(包括我),但也有很多谁觉得这简直是一个面向对象的,可以接受的方式来做到全局。

Tricky. There are plenty of people who feel that singletons are essentially an anti-pattern like you said (me included), but there are also a lot who feel that it is simply an OOP-acceptable way to do globals.

如果面试官是该阵营的话,是的,我认为他是错的,但可能不是在接受采访时说的最好的事情。 ;)

If the interviewer is in that camp then yes, I think he's wrong, but that might not be the best thing to say during the interview. ;)

所以我可能会尝试保持中立,并坚持事实。你不知道你的面试官落在哪个阵营,所以坚持不争的事实。什么是单身吗?并表现出使用,坚持少数情况下,大多数人都同意,单是一个可以接受的答案。或说明你的经验(因为人们无法不同意这一点无论是)。

So I'd probably try to be neutral and stick to the facts. You don't know which camp your interviewer falls in, so stick to the indisputable facts. What does a singleton do? And to demonstrate usage, stick to the few cases where most people can agree that a singleton is an acceptable answer. Or explain your experience (since people can't disagree with that either).

不过,无论你是对或反对单身人士接受记者采访时很可能不是讨伐对于事业的好时机。 ;)

But whether you're "for" or "against" singletons, an interview is probably not the right time to crusade for that cause. ;)

这篇关于如何回答面试问题:什么是单身,你会如何使用呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆