Re: Method chaining with generics



Thomas Weidenfeller wrote:
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.

Not necessarily. If assuming that the implementation of the list returned keeps bsc in sync, it's fine. List doesn't have to imply ArrayList/LinkedList.


Law of Demeter, perhaps.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
.