Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #28726

Re: Queue and Map interface

From Philipp Kraus <philipp.kraus@flashpixx.de>
Newsgroups comp.lang.java.programmer
Subject Re: Queue and Map interface
Date 2014-06-14 07:52 +0200
Organization 1&1 Internet AG
Message-ID <lngnu2$etd$1@online.de> (permalink)
References <lnfoa3$8sn$1@online.de> <lnfql9$hnq$1@dont-email.me>

Show all headers | View raw


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<A,B> extends myAbstractClass implements Map<A,B>,
>> Queue<B> {}
>> 
>> 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<A,B>
> in an outer class, one that also contains a Queue<B> 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<K,V> {

	private myMap implements Map<K,V> {}
	private Queue implements Queue<V> {}

	public Map<K,V> getMap() {}
	public Queue<V> 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

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Queue and Map interface Philipp Kraus <philipp.kraus@flashpixx.de> - 2014-06-13 22:52 +0200
  Re: Queue and Map interface Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-06-13 17:32 -0400
    Re: Queue and Map interface markspace <markspace@nospam.nospam> - 2014-06-13 16:52 -0700
    Re: Queue and Map interface Philipp Kraus <philipp.kraus@flashpixx.de> - 2014-06-14 07:52 +0200
      Re: Queue and Map interface Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-06-14 08:41 -0400

csiph-web