#59 SharedList

Closed
opened 4 years ago by ranides · 3 comments
ranides commented 4 years ago

We should have a list wrapper which offers access to internal/source list and allows exposing its' content to public consumers in a safe way.

"Safe" means, that every time returned public list must behave like defensive, shallow copy.

Because of performance reasons, we wont create shallow copies over and over again, but return protected views.

We should have a list wrapper which offers access to internal/source list and allows exposing its' content to public consumers in a safe way. "Safe" means, that every time returned public list must __behave__ like defensive, shallow copy. Because of performance reasons, we wont create shallow copies over and over again, but return protected views.
ranides commented 4 years ago
Owner

class SharedList will have fields:

  1. source: List
  2. view: PublicList
  3. data: PrivateList

The source one must be hidden from everyone.

PublicList will delegate read operations to "source" or "copy of source". That means reference to target list can be replaced by new ArrayList(source) at any time. After replacement, SharedList will clear their (2) field. From this moment, PublicList will be detached, almost ordinary, independent list adapter.

Replacement will be triggered by any write operation on PublicList or PrivateList. PrivateList is simpler. It will always delegate all operations to source, but write operations will work like "just listeners".

Please note, that it is pointless of creating SharedList from source which will be accessible from outside world, because SharedList won't have any way to observe change of data and detach PublicList correctly.

class SharedList will have fields: 1. source: `List` 2. view: `PublicList` 3. data: `PrivateList` The source one must be hidden from everyone. PublicList will delegate read operations to "source" or "copy of source". That means reference to target list can be replaced by new ArrayList(source) at any time. After replacement, SharedList will clear their (2) field. From this moment, PublicList will be detached, almost ordinary, independent list adapter. Replacement will be triggered by any write operation on PublicList or PrivateList. PrivateList is simpler. It will always delegate all operations to source, but write operations will work like "just listeners". Please note, that it is pointless of creating SharedList from source which will be accessible from outside world, because SharedList won't have any way to observe change of data and detach PublicList correctly.
ranides commented 4 years ago
Owner

Maybe whole functionality is pointless and we should accept the fact, that we can't control changes inside source? We should just implement something different, called: "FastCopy" which will detach on their own, but it won't detach eralier.

I mean: FastCopy will tell to everyone: "I am just a view, until you try to modify me"

Maybe whole functionality is pointless and we should accept the fact, that we can't control changes inside `source`? We should just implement something different, called: "FastCopy" which will detach on their own, but it won't detach eralier. I mean: FastCopy will tell to everyone: _"I am just a view, until you try to modify me"_
ranides commented 4 years ago
Owner

CopyList done

CopyList done
Sign in to join this conversation.
No Milestone
No assignee
1 Participants
Loading...
Cancel
Save
There is no content yet.