Well, there is a solution, to some extent. Type Hierarchy.

List should have just had lookup and 'make a copy of self' methods.
Then, MutableList, which extends it, should have had the add, addAll,
remove, removeAll, clear, and other mutating methods on them.

Iterator should have come in two varieties. One with remove, one
without. Etcetera.


Not saying that it's a great idea, nor saying that its easy or even
smart to attempt to refactor the java collections API at this point to
accomodate all this, just that it's a solution that fits with java
language design. (though technically splitting List.java into
ImmutableList.java and List.java can be done omni-compatibly, but then
making Collections.unmodifiableList return an ImmutableList cannot be
done without breaking lots and lots of code, so what's the point?)

On Mar 4, 3:24 pm, Jeff Grigg <[email protected]> wrote:
> To take the discussion in a more serious direction...
>
> --- Michael Neale <[email protected]> wrote:
>
> > [...] I think freeze was more for dynamic languages like ruby and
> > groovy [...]
>
> Yes, the "freeze" concept seems more appropriate for dynamically typed
> languages than for statically typed interface-based languages.
>
> Java "supports" a minimal variant of this idea in the Collections
> class with the "unmodifiable*" methods (and 'public static EMPTY_*'
> fields), and the well-documented standard
> UnsupportedOperationException that Iterator.remove() can call.  But
> having a class "advertise" that it implements an interface, and then
> throwing "does not implement" exceptions in some of the methods of the
> interface violates the Liskov Substitution Principle 
> (http://www.c2.com/cgi/wiki?LiskovSubstitutionPrinciple), which is based on
> the idea that client code should not have to concern itself with the
> implementation (or partial lack thereof!) of an interface.  It's a
> Java language design issue with no obvious solutions, at this point.
>
> This generally suggests using builder patterns in statically typed
> languages.  http://www.c2.com/cgi/wiki?BuilderPattern
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to