Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!takemy.news.telefonica.de!telefonica.de!feed.news.schlund.de!schlund.de!news.online.de!not-for-mail From: Philipp Kraus Newsgroups: comp.lang.java.programmer Subject: Re: Queue and Map interface Date: Sat, 14 Jun 2014 07:52:01 +0200 Organization: 1&1 Internet AG Lines: 54 Message-ID: References: NNTP-Posting-Host: p3e9e6ea5.dip0.t-ipconnect.de Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Trace: online.de 1402725122 15277 62.158.110.165 (14 Jun 2014 05:52:02 GMT) X-Complaints-To: abuse@einsundeins.com NNTP-Posting-Date: Sat, 14 Jun 2014 05:52:02 +0000 (UTC) User-Agent: Unison/2.1.10 Xref: csiph.com comp.lang.java.programmer:28726 On 2014-06-13 21:32:20 +0000, Eric Sosman said: > On 6/13/2014 4:52 PM, Philipp Kraus wrote: >> Hello, >> >> I would like to create a class which implements a Map and a Queue with >> >> class myMapQueue extends myAbstractClass implements Map, >> Queue {} >> >> The problem is the remove(Object) method, because the method is defined >> in the Queue and the Map >> interface in the Queue with boolean remove(Object) and in the Map with V >> remove(Object), so I get >> a "clash error". How can I solve this problem. > > "Favor composition over inheritance." -- Bloch > > In short, I don't believe you can do what you want -- not in the > way you want to do it. An alternative might be to implement Map > in an outer class, one that also contains a Queue implementation as > an inner class. The outer class would also have a getQueue() method > to return an instance of the inner class -- whether that's a new > instance created on the fly or a single instance that's created once > per outer class is up to you. > > For even more "favoritism," you could have the outer class > implement neither Map nor Queue, and delegate both those interfaces > to inner classes. Thanks you both for the idea, but it is not nice to do this with different inner structures, because I need on the class the interface of Map and Queue, because an object of myMapQueue should use with the Java Map or Queue structure. On the idea: class myMapQueue { private myMap implements Map {} private Queue implements Queue {} public Map getMap() {} public Queue getQueue() {} } I need always the getMap or getQueue call before I can use the internal datastructure. Thanks a lot for the idea, but I need first to redfine my classes for a better code structure Phil