×

Loading...

How to learn some patterns

本文发表在 rolia.net 枫下论坛Sailor suggested me to posting something about patterns. Let me try to do this job.

Pattern is actually not mysterious. It implies that things occur repeatedly in diffirent places. Naively, the following two patterns can give us some impression about patterns

...ABCABCABCABC....
...123123123123....

This is trivial. Now consider two more interesting cases.

1) Let me assume that Jessy and Deberah
are taking the elevator. Both of them want to
go to the fourth floor. Jessy pushes button 4.
Deberah does not know that and she push button 4, too.
2) Now let all of us visit the gentleman's room. After a gentleman released his internal pressure, he moved his body.
The sensor for the flusher detects his motion aand triggers the flushing device. However, this gentleman still pressed the flsuhing button.

1) and 2) describes two diffirent things in two different contexts. If we thinkthem over, we observe that they have some similarity. In both cases, the second action(Deberah's pushing button 4 and the gentleman's pressing flushing button) does not bring any real effects. In rea implementation, one may check first checkes some status and then make decision. Let us assume we use Java. If the elevator is already moving to the fourth flour, we may have the system throw an exception as Deberah pushes button 4; Likely, the system may throw an exception as that gentleman presses the flushing button.
------The thing I am talking about can be called Exception Pattern.

Patterns may be small, and may be big. Some patterns need to work with other patterns. If one knows some pattern, it is definite a big plus. However, doing a project is not simply applying patterns. Without strong analysing ability, one cannot pick up any patterns. Sometimes, people may stop you and ask you: "Hay, I have such a question, blahblah..., what patterns should I use?" The answer is probably "Sorry, I have no idea..."

I understand most of us cannot afford buying English books. So I suggest 1) downloading
Thinking in Patterns from www.bruceeckel.com. This books describes most of basic patterns and gives examples in Java. 2) Visit www.gamelan.com and read the articles about Patterns. Again, the examples on this site are written in Java.

Historically, the Gang of Four pioneered the research on the patterns. Their book is a bible (with C++ example). Their contributions to patterns have been recapulated numerous times by other authors. I don't think I need to read this bible. Understanding patterns is not as simple as reading some books about pattern. It is a long-time process to get used to think in patterns.

In the job interview, if you are applying for senior-level positions, people may ask you questions about patterns. If you are at entry level, don't worry---you have more opportunities to learn.更多精彩文章及讨论,请光临枫下论坛 rolia.net
Sign in and Reply Report