- تاریخ ارسال : دوشنبه
- بازدید : 572 مشاهده
What are Design Patterns?
Sitting at your desk in front of your workstation, you stare into space,
trying to figure out how to write a new program feature. You know
intuitively what must be done, what data and what objects come into play,
but you have this underlying feeling that there is a more elegant and
general way to write this program.
In fact, you probably don’t write any code until you can build a picture in
your mind of what the code does and how the pieces of the code interact.
The more that you can picture this “organic whole,” or gestalt, the more
likely you are to feel comfortable that you have developed the best
solution to the problem. If you don’t grasp this whole right away, you may
keep staring out the window for a time, even though the basic solution to
the problem is quite obvious.
In one sense you feel that the more elegant solution will be more reusable
and more maintainable, but even if you are the sole likely programmer,
you feel reassured once you have designed a solution that is relatively
elegant and that doesn’t expose too many internal inelegancies.
One of the main reasons that computer science researchers began to
recognize design patterns is to satisfy this need for elegant, but simple,
reusable solutions. The term “design patterns” sounds a bit formal to the
uninitiated and can be somewhat offputting when you first encounter it.
But, in fact, design patterns are just convenient ways of reusing objectoriented
code between projects and between programmers. The idea
behind design patterns is simple—write down and catalog common
interactions between objects that programmers have frequently found
One of the frequently cited patterns from early literature on programming
frameworks is the Model-View-Controller framework for Smalltalk
(Krasner and Pope 1988), which divided the user interface problem into
three parts, as shown in Figure 1-1. The parts were referred to as a data