[ajug-members] design theory
521
521 at ofig.org
Mon May 5 08:19:51 EDT 2008
thanks laura, you understood my-point in asking that question; good collection, set, list, and map sentence(s) too...
barclay
On Sun, 4 May 2008 23:06:58 -0400, Laura Woody wrote
> Mcdaniel,
> Not as basic'ish a question as you think, considering how many developers claiming years of java experience seem to miss the concept in practice.
>
> At it's most basic, design to interface means to use the most generic reference you can to an object. My favorite practical example is the java.util package. If, for example, you create a method to return a group of objects, you should declare the return type as the most generic one possible - java.util.Collection if your clients do not need to know anything about the relationship of the objects in the Collection. java.util.Set if the items are a unique set and order doesn't matter, java.util.List if order is important, or java.util.Map if it is a collection of key-pairs. Coding to the interface gives your code, and any extensions to your code the most flexibility in implementation. If you return the implementation.
>
> Of course the next step is to always be looking for the generic interfaces in your code, and extracting those interfaces where possible. Again to give yourself the most flexibility in future implementations.
>
> I agree that too often the examples are esoteric. I think I learned the most by studying the "Gang of Four" design patterns book, where they are solving real world code problems. I also had luck surfing online for good discussions of this topic.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.ajug.org/pipermail/ajug-members/attachments/20080505/b1a86495/attachment.html
More information about the ajug-members
mailing list