I answered a question regaurding an ImmutableMap
. I suggested using the Proxy pattern.
The problem with this is that Map
contains a put
method, which would throw an UnsupportedOperationException
. Replacing other instances of Map
with ImmutableMap
would break the Liskov Subsitution principle. Not only that, the need to declare put
and putAll
[violates the interface segregation principle]
Technically, there is no way to replace a Map
instance with ImmutableMap
, since Map
is simply an interface. So my question is:
Would creating an ImmutableMap
using the Map
interface be considered breaking the LSP, since Map
contains a put
and putAll
method? Would not implementing Map
be considered an "Alternative Classes with Different Interfaces" code smell? How would one create an ImmutableMap
that abides by the LSP yet doesn't contain code smells?