[ajug-members] design theory

Barry Hawkins barry at alltc.com
Mon May 5 10:15:21 EDT 2008


This is turning into a great segue for this month's meeting :-).

Barry

On May 4, 2008, at 11:06 PM, 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.
[...]

-- 
Barry Hawkins
All Things Computed
site: http://www.alltc.com
weblog: http://www.yepthatsme.com







More information about the ajug-members mailing list