Re: Method chaining with generics



iksrazal@xxxxxxxxxxxx wrote:
Allow my code to explain:

        Bsc bsc = BscHelper.createBsc();
        SiteType siteType = BscHelper.createSiteType(id,name);
        bsc.getSite().add(siteType);

getSite() returns List. It was written without generics in mind.

The real error is an architectural design bug. You have a class Bsc which contains a list of sites, and you hand out that list to the public for manipulation. This seriously breaks encapsulation. Class Bsc should instead get a method addSite(), and do all the list handling internally.


/Thomas

--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
.