After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 557719 - [Libgee] Collection and MutableCollection should be separate
[Libgee] Collection and MutableCollection should be separate
Status: RESOLVED FIXED
Product: libgee
Classification: Platform
Component: general
git master
Other All
: Normal enhancement
: ---
Assigned To: libgee-maint
libgee-maint
Depends on:
Blocks:
 
 
Reported: 2008-10-24 09:44 UTC by Maciej Katafiasz
Modified: 2011-01-04 14:52 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
0001-Split-between-read-only-collections-interfaces-and-m.patch (29.99 KB, patch)
2009-07-26 20:29 UTC, Maciej (Matthew) Piechotka
none Details | Review
0001-Split-between-read-only-collections-interfaces-and-m.patch (37.79 KB, patch)
2009-08-13 10:38 UTC, Maciej (Matthew) Piechotka
none Details | Review

Description Maciej Katafiasz 2008-10-24 09:44:51 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.
Comment 1 Maciej (Matthew) Piechotka 2009-07-26 18:41:19 UTC
AFAIU the actual tree issomething like:

ReadOnlyCollection* --> Collection <-- MutableCollection
         ^    ^           ^    ^           ^       ^
         |    |           |    |           |       |
ReadOnlySet* -)-------> Set <--)------ MutableSet  |
              |                |                   |
             /                 /                   |
ReadOnlyList* -----------> List <---------MutableList

Where * are wrapper classes.
Comment 2 Maciej (Matthew) Piechotka 2009-07-26 19:22:22 UTC
I started to implement it - it seems that other parts will also benefit (such as key sets/value sets).
Comment 3 Maciej (Matthew) Piechotka 2009-07-26 20:29:14 UTC
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).
Comment 4 Maciej (Matthew) Piechotka 2009-08-13 09:39:33 UTC
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.
Comment 5 Maciej (Matthew) Piechotka 2009-08-13 10:38:44 UTC
Created attachment 140642 [details] [review]
0001-Split-between-read-only-collections-interfaces-and-m.patch
Comment 6 Maciej (Matthew) Piechotka 2011-01-04 14:52:20 UTC
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