Java Reference
In-Depth Information
A good goal is to be able to answer these questions without referring to this topic. It is also
good exercise to write down your answers and to share your answers with a colleague.
Weave Patterns into Your Code
A primary purpose for learning design patterns is to become a better developer. Think about
how to use patterns in the code base you work with most often. Here, you have two choices:
Apply design patterns as you add new code, or apply design patterns through refactoring. If
part of your code is complex and difficult to maintain, you may be able to improve it by
refactoring the code and using a design pattern. Before diving into such a project, make sure
that you have a customer for the result. Also, before you change the code, be sure to create an
automated test suite for the code that you are refactoring.
Now, suppose that you understand the patterns you have studied and are determined to use
them carefully and appropriately. How do you find an opportunity? Some opportunities arise
fairly frequently. If you're looking for a chance to apply design patterns, consider the
following.
Does your code base have any complex code that deals with the state of a system or
the state of the application user? If so, you may be able to improve the code by
applying the S TATE pattern.
Does your code combine the selection of a strategy with the execution of that strategy?
If it does, you may be able to make the code better by using the S TRATEGY pattern.
Does your customer or analyst supply you with flowcharts that translate into code that
is difficult to comprehend? If so, you can apply the I NTERPRETER pattern, letting each
node of the flowchart become an instance of a class in the interpreter hierarchy. You
can thus provide a direct translation from the flowchart to the code.
Does your code contain a weak composite that doesn't allow children to be composites
themselves? You may be able to strengthen such code with the C OMPOSITE pattern.
Have you encountered relational-integrity errors in your object model? You may be
able to prevent them by applying the M EDIATOR pattern to centralize the modeling of
object relations.
Does your code have places where clients are using information from a service to
decide which class to instantiate? You may be able to improve and to simplify such
code by applying the F ACTORY M ETHOD pattern.
By learning design patterns, you have developed a rich vocabulary of design ideas. If you are
on the lookout for opportunities, it probably won't be long before you find a design that you
can improve by applying a pattern.
Keep Learning
Somehow, you had the opportunity, drive, and ambition to acquire and to read this topic. All I
can say is, keep it up! I think the best advice for developers is to decide how many hours a
week you want to spend on your career. Take five hours off the top and pay yourself first.
Spend that time away from the office, reading topics and magazines or writing software
related to any topic that interests you. Make this practice as regular as your office hours. Treat
this aspect of your career seriously, and you'll become a much better developer, and you'll
probably find that you enjoy your job more.
Search WWH ::




Custom Search