General Java Questions III
I am very new to design patterns and just bought the GoF book to learn about it.
But as I complete the first couple of chapters right away, I see that they have 23
different patterns and I would be lost and forget everything very soon if I sequentially
(page by page) read the entire book!.
Do any of you have recommendations on how to proceed with this book so that I  ll
remember at least some of them by the time I am done with the book? I can see that
many of the classes in java API use composition, facade etc...
But other than that I don t think I  ll be able to gather anything unless I am able to
remember where & when to use particular pattern A, B or C...
Answer: Glad to hear you got the GoF book, it s a great reference manual for
patterns. As you ve found, however, it s a bit heavy to just "read." What I recommend
to people is that they pick a few of the easier, more commonly used patterns:
Singleton is a no brainer that pops up a lot. Adapter tends to get used here and there
and isn t that difficult to understand. If you re doing Swing, then definitely go learn the
Observer pattern. It ll help to keep you from mixing data and interface code. Once
you ve learned three or four and have used them a few times, then as you start new
projects, look back to the text to see if there are opportunities in your project where
other patterns can be used.
You ll find that over time you ll use more and more of the patterns (some a lot more
than others, obviously). I ve often found cases where I missed a pattern during
design and had "the light go on" after I d written a bunch of code and realized I was
either using a known pattern by accident, or could have used a pattern to my
advantage. When possible, I then go back and adjust the design/code to match the
pattern.
Keep in mind that the patterns generally don t appear as "absolute." It s expected
that you may have variations to satisfy your application s needs.  
It s really helpful to others, however, if you make a quick note in your design
doc/code about what pattern you were using (which helps them learn patterns too,
and helps them understand what you were up to if they know the pattern already).
  
Rico Trooper
 Q: When I used java.util.Hashtable, I also used interface Enumeration. But I
found that this interface contains defined methods.
How can an interface contain defined methods? Isn t an interface supposed to hold
abstract methods only?
Answer: 
> How can an interface contain defined methods?
No.
> Isn t an interface supposed to hold abstract methods only?
Yes. (and fields). I m not sure why you think Enumeration contains defined methods,
since it does not (I checked the source to be sure). Keep in mind that an
implementing class is also of type Enumeration. So Hashtable s keys method which
returns an Enumeration will actually be returning an inner class that implements
Enumeration
(and therefore defining hasMoreElements and nextElement in a manner that is
specific to traversing a Hashtable). 
If this doesn t help, maybe you could clear up what you mean by Enumeration having
file:///F|/a_jsite/350_tips/general_java III.htm (7 of 9) [2001 07 08 11:24:53]






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved