s**********a 发帖数: 78 | 1 我觉得design patterns和data structure/algorithm不同,是实践性的东西,没有用过
很难说清楚怎么用,利与弊。 |
|
s**********a 发帖数: 78 | 2 我的经验(被面和面别人)是设计题分几类。
一类是就system而言,如CD player, Hotel booking system
另一类是design an end to end solution e.g. client-server architecture。
大部分面试都是这两类,前一类是OOD/OOA,后一类是看你的design or whiteboard
draw是不是make sense e.g. network efficiency, security, protocol design etc.
至于detail design pattern并不是这些设计题的重点啦。 |
|
i**********b 发帖数: 77 | 3 Thank you. Still I don't understand how this can be implemented. I had
understood how it's used though.
A typical Decorator design pattern is implemented using composition. The
Decorator and the Component (to be decorated) shall have the same interfaces
. The decorated component can be treated as an original component.
However, in this case, BufferedInputStream and DataInputStream both added
additional functions to FilterInputStream. If a FilterInputStream is
decorated by BufferedInputStream fir |
|
y****n 发帖数: 579 | 4 如果是入门的话,Head First Design Patterns不错。 |
|
g*********g 发帖数: 124 | 5 I have a pdf book, the famous one for C++ design pattern. It is 25oM. let me
know how I can send to you. |
|
r***h 发帖数: 70 | 6 本人开学最后一年,准备1年后毕业,对工业界的情
况不了解。真心请教一下我做的方向和背景应该去申
请什么样的职位,有哪些公司可以申请这种职位?
先说一下背景,本科国内不错的学校cs,美国50-
100名cs master,现ph.d在读。RA期间做
Medical Imaging, Pattern Recognition,
Computer Vision方向,4篇一作文章除了1
个Transaction的期刊外都比较一般,估计毕业时
会有6篇一作。在美国公司做过1年多,其他没什么
工作经验。编程上只熟悉C++和Matlab。
但是选这个方向是比较喜欢做些有点idea的东西。
开始做的时候就听有人说工作好找,有人说不好找,
当时也没想太多就上手做了,觉得还蛮有意思。所以
倾向于做些R&D的Coding,虽然纯粹的Coding的工
作也可以接受。请教有经验的朋友,我该去申请什么
样的职位,有哪些公司在做这个方向?
谢谢! |
|
f******n 发帖数: 90 | 7 那里可以找到design pattern的一些免费的video? |
|
d*********i 发帖数: 628 | 8 握手~我老师也是做pattern recognition的
不过带我做的是image processing的东西,和ai结合的
似乎不是很好找工作吧,感觉一般软工都不用这些 |
|
d**e 发帖数: 6098 | 9 贴出来看看?
这个跟strstr类似吧?
O(nm)
n = strlen(string)
m = strlen(pattern) |
|
i**********e 发帖数: 1145 | 10 hmm...
This problem seem not that straightforward. Lots of tricky cases to handle.
Anyone who can code this in 20 minutes and got it correct, I salute you.
I have added some more test cases below:
str = "mississippi"
pattern result |
|
P********l 发帖数: 452 | 11 可以和ihasleetcode的算法同归于有限状态机一类。再往下走就是对pattern进行编译
了。 |
|
j*****g 发帖数: 223 | 12 大哥,
1)能不能用点通俗的变量名?haystack/needle俺看不懂
2)matchdots,你是不是肯定text和dstr的长度一样?一个简单的字符串比较写成这样
,会不会out of bound and access violation呢?
3)strstrwilddots没有error/NULL checking
4)matched好像一直在++,怎么后面的比较都是matched == 1?
5)你的解答好像有点文不对题?说的是一个pattern能不能match整个string, 不时一
部分.
不过大概的意思我看懂了,是这个贪心算法. |
|
j*****g 发帖数: 223 | 13 Yes.
Since the problem reduces to do a bunch of strstr, so it should be linear to
O(n+m) where n is string length and m is the pattern length.
J |
|
a****n 发帖数: 1887 | 14 mvc 是设计方法用来分离UI和data, 没在DP书上出现过, 不过里面确实需要用到一些
pattern, 比如observer, factory, etc |
|
a**********2 发帖数: 340 | 15 如果singleton pattern的getInstance()方法定义成这样有问题吗?
class A
{
public:
static A* getInstance()
{
static A a;
return &a;
}
}; |
|
c******n 发帖数: 4965 | 16 I don't see a problem with this
if you compile this code with gcc, and then decompile the resulting
code, the assembley looks like:
lock(some_lock)
if ( not_initialized ) {
a = new A();
not_initialized = false;
}
unlock(some_lock)
in fact, for the java version, the book "effective java" actually
recommends the idiom
class A {
static A ins = new A();
static A getInstance() { return ins;}
}
the java version has a bigger problem though: you can't control when
the ins is initialized, thus agai... 阅读全帖 |
|
s******g 发帖数: 46 | 17 刚开始找工作,面试了几家,好几次被问到了这道题,想来应该是经典题了,可是搜了
一下,没发现很直接的答案,所以想请教大家。
题目是:
有一个不定长的char string (S1),都是0,1组成;另外一个string (S2), 也是0,1
组成,可以认为是pattern,问S1中是否含有S2
e.g S1 = 11100011 10101011 11111111 10000100 ( 4 bytes, '11100011' is 1 byte)
S2 = 00111010
the answer is ture, 1110"00111010"1011
希望讲清楚了,先谢谢了 |
|
f*******4 发帖数: 1401 | 18 Head First, I like it, 本科学design pattern就是用的这个书 |
|
D*********y 发帖数: 876 | 19 多谢推荐!
要是早点看到楼主的帖子就好了
我刚买了一本head first design pattern |
|
x***y 发帖数: 633 | 20 I remember in an interview last year I was asked when we should use singlton
design pattern,and that interviewer expected a better answer than "the
class can only have one instance"..... |
|
x*****p 发帖数: 1707 | 21 Actually, singleton patterns are used in many places. For example, in
Cairngorm MVC, a singleton for ModelLocator class is a must. If you are
enrolled in some big project, you will find more examples for singleton
objects.
singlton |
|
i**9 发帖数: 351 | 22 谁能聊一聊amazon 那个经典的furniture(table ,chair ,wood_chair, steel_chair,
wood_steel_chair,wood_table,steel_table)该用什么design pattern?怎么 design更
有效率? |
|
w*********b 发帖数: 25 | 23 本人EE的,对C++了解,但是写程序都是C为主。
现在有个职位说是要用C++在linux下面编程,做一些
wireless的系统控制之类的东西。提到了要了解
Design pattern, multithread之类的,真心求教
编程高手,在短时间该怎么准备这方面的面试??
(因为没几天就要onsite了) |
|
|
f**********t 发帖数: 1001 | 25 快被design题搞疯了. 在复习时间不是很多的时候有啥快一点的办法么? 比如选几个
pattern看. 看那本书连续看一个星期也看不完啊 :( |
|
b*******y 发帖数: 2048 | 26 head first design pattern
非常好,不过是java... |
|
r*******y 发帖数: 1081 | 27 it is not OK to return a copy of the object in the singleton pattern.
need to return a reference or a pointer |
|
r*********2 发帖数: 88 | 28 double check locking pattern. |
|
g**********y 发帖数: 14569 | 29 字符串长N, 对N的所有小于N的因数搜索,这个就是N*log(N)的。
public boolean isRepeated(String word) {
int N = word.length();
for (int i=1; i
if (N%i == 0 &&
Pattern.matches("^(" + word.substring(0, i) + ")*$", word))
return true;
}
return false;
} |
|
d*******d 发帖数: 2050 | 30 不懂java,能不能解释一下这句话.
Pattern.matches("^(" + word.substring(0, i) + ")*$", word) |
|
h******3 发帖数: 351 | 31 assume s = word.substring(0, i)
examine whether the string "("+s+")" matches pattern or not. ^ indicates
beginning of a string, $-ending. |
|
g**********y 发帖数: 14569 | 32 见hunter33解释,就是看string是不是pattern的重复,这个是O(n)的操作,自己写实
现也很简单。 |
|
h******3 发帖数: 351 | 33 I understand one of the reasons that the code can be concise is:
whether the string includes repeated pattern. That's why we care about the
factor of N. And the running time is Nlog(N). |
|
g**********y 发帖数: 14569 | 34 用筛法算素数,只需要判断所有的N/p, p是素数。
public boolean isRepeated(String word) {
int N = word.length();
boolean[] composite = new boolean[N+1];
for (int i=2; i<=N; i++) {
if (!composite[i]) {
if (N%i == 0 &&
Pattern.matches("^(" + word.substring(0, N/i) + ")*$", word)
) return true;
for (int j=i*2; j<=N; j+=i) composite[j] = true;
}
}
return false;
} |
|
m*******y 发帖数: 904 | 35 Can anybody share some good materials/links for classical String Pattern
Matching problems?
Lets discuss and learn together. |
|
|
y*******g 发帖数: 6599 | 37 iterator和smart pointer完全不同吧,smart pointer是为了防止memory leak,
iterator是提供一个访问collection的方式。
没有太多project经验的话,
看的时候可以结合design principles一起看,比如open for extension but closed
for modification
http://www.oodesign.com/design-principles.html
也可以学习的时候想想现有的framework 比如j2ee, iPhone sdk等等是怎么应用这些
design pattern的, |
|
D*******e 发帖数: 151 | 38 design pattern是真正让我觉得编程有美感的东西,学的时候就觉得这样设计很
elegant,太聪明了 |
|
|
g**********y 发帖数: 14569 | 40 第三层?手中无剑,心中有剑。
就象足球里的马拉多纳,最可怕的不是那些高光上完成的匪夷所思的动作,而是在大多
数时候,他能在最短的时间里用合理的动作衔接处理球,打击对方的薄弱环节。
软件设计里,最痛苦的地方就在:你需要不停地应对不断变化的情况。你怎么设计能够
使得整个框架在情况变化时,能够以比较小的代价应付变化。那些pattern就是总结常
见的经典思路。
到了这层的高手,脑子不拘泥在名词术语里,给出问题,他很快就能告诉你合理的方案
。不在乎这个解是否有个响亮的名字,关键是:在现实的约束条件下,这个解很有效,
易写易维护。
我见过很多人,侃起来一套一套的,但其实没什么底子,一旦真写就漏馅,相信大家都
碰到过不少这种人。所以就容易误认为设计就是侃。
遇到设计高手,人家很短时间就解了让你头疼的东西,那时你就会更深地体会什么是设
计。 |
|
k*******e 发帖数: 47 | 41 我design pattern一点也不会啊,可是面试的时候问的特别多。这个不是很难的吧,有
什么资料速成一下? |
|
e*********l 发帖数: 136 | 42 Head first design pattern |
|
z****u 发帖数: 104 | 43 我就用过这么一个 pattern,还是冷门... |
|
F*****e 发帖数: 331 | 44 问题是关于decorate pattern(装饰模式),就是给一个人一件一件穿衣服的程序,基
类是人,第一个子继承类是Finery(服饰),Finery下面有3个子继承类分别是:
Tshirt Sneaker Trousers。 程序中用到了装饰模式的思想,和一堆虚函数和覆写函数
,关于这些函数和覆写函数是怎么跑的我看不明白,贴上代码:请牛人观观!
class Program
{
static void Main(string[] args)
{
Person Alice = new Person("Alice");
Console.WriteLine("\n Alice's beautiful dress are:");
Sneakers sneaker = new Sneakers();
BigTrouser trouser = new BigTrouser();
TShirts tshirt = new TShirts()... 阅读全帖 |
|
v***a 发帖数: 365 | 45 Finery 类里存了protected Person component;
比如:tshirt 存的 Person 是 trouser;
tshirt 调用 base.Show() 调用的是 Finery 的 show(),然后 Finery 调用的是 他存
的那Person 的 Show(),也就是 Trouser.show(),
然后 recursive
design pattern 的书都有讲的,而且讲得很详细,
说白了就是一个Hook,在调用想要调用的函数之前,先调用你的,然后你再替它调用原
始函数 |
|
v***a 发帖数: 365 | 46
当然可以反过来,是平行的概念,这也就是之前说的 decorator pattern的特点,他们
是平行的,松耦合的
只是实现的时候,用了包含,或者说,tshirt 有个指向上级的 pointer, 而 tshirt
不管那个pointer 是谁,也不管tshirt自己本身被谁指向,他只管做完自己的事情之后
,调用 pointer 指向的东西 |
|
c**********e 发帖数: 2007 | 47 这个Strategy design pattern的例子为什么人为得弄得这么复杂?
#include
#include
#include
using namespace std;
class Strategy;
class TestBed
{
public:
enum StrategyType
{
Dummy, Left, Right, Center
};
TestBed()
{
strategy_ = NULL;
}
void setStrategy(int type, int width);
void doIt();
private:
Strategy *strategy_;
};
class Strategy
{
public:
Strategy(int width): width_(width){}
void format()
{
char line[80], wo... 阅读全帖 |
|
t*****j 发帖数: 1105 | 48 同疑问。貌似他们的思想其实是一样的...就是把不同dimension的
variation decouple下。感觉好些pattern其实都是这个中心思想。 |
|
z****e 发帖数: 54598 | 49 顾名思义啊
结构模式其本意是在告诉你结构的差异和模式
而行为模式本意在于强调行为的差异和模式
bridge的本意是利用两个abstract的类,一个abstract class和一个interface
把相同的部分和不同的部分分离,然后用不同的类继承这两个东西来实现
以达到实现共同部分和不同部分拆分实现的目的
本意就是强调结构,如何实现,也就是具体的实现类是这个模式中最无关紧要的部分
结构上的不同,所有的结构模式都是在告诉别人结构上的差异
可以看作是一堆abstract class和interface的关系,具体怎么实现
其实样例代码如果不写那些具体的实现类可能还更清晰点
而strategy模式是行为,行为在java里面就是function
本身用一个interface就搞定了
几乎所有的behavioral模式的实现都很简单,不少是别人写好了,用就行了
比如iterator,所以这个模式最重要的其实是其实现类,至于调用interface的那个具
体类
那个无关紧要了,不要也没什么大不了的,只不过这个模式需要一个类来存放一些
state之类的
所以样例代码不好直接扔掉这个类,但是加上去... 阅读全帖 |
|
g*******a 发帖数: 149 | 50 有谁推荐一下design pattern的书?比较简单易懂的入门级别的不太厚的书?谢谢啊! |
|