GNOME Bugzilla – Bug 557719
[Libgee] Collection and MutableCollection should be separate
Last modified: 2011-01-04 14:52:20 UTC
Currently the type hierarchy looks like that: Iterable <---- Collection ^ | | ReadOnlyCollection That means ReadOnlyCollection unnecessarily inherits all the mutator methods, which it then has to patch out with assert_not_reached(). The API should look like this instead: Iterable <---- Collection <---- MutableCollection ^ | | ReadOnlyCollection This way ReadOnlyCollection only has relevant methods, subclasses are truly substitutable, and the amount of extra code is close to zero, as all the assert_not_reached() calls can be simply deleted.
AFAIU the actual tree issomething like: ReadOnlyCollection* --> Collection <-- MutableCollection ^ ^ ^ ^ ^ ^ | | | | | | ReadOnlySet* -)-------> Set <--)------ MutableSet | | | | / / | ReadOnlyList* -----------> List <---------MutableList Where * are wrapper classes.
I started to implement it - it seems that other parts will also benefit (such as key sets/value sets).
Created attachment 139247 [details] [review] 0001-Split-between-read-only-collections-interfaces-and-m.patch A simple patch. Please note that I added myself as author to the interfaces as they were heavily impact. However - please feel free to remove it (I'm also not sure about copyright line).
I'm updating the patch against the master and with current number of abstract* classes I belive that current solution leads us to dimond-shaped inheritance. Therefore I ask to add dependency to bug 590306.
Created attachment 140642 [details] [review] 0001-Split-between-read-only-collections-interfaces-and-m.patch
I've implemented it in slightly different way commit f3d4ac63d29d04e58bdd311b3ebaffbfd6ebae9d Author: Maciej Piechotka <uzytkownik2@gmail.com> Date: Tue Jan 4 15:10:52 2011 +0100 Add read_only property to Iterator and MapIterator commit 4df3e3a76a3158995e1f37a3c6984ff9aac00f13 Author: Maciej Piechotka <uzytkownik2@gmail.com> Date: Tue Jan 4 15:46:13 2011 +0100 Add read_only method to Collection, Map and MultiMap