eShopOnWeb Architecture (7/16) – encapsulates navigation collections so consumers can’t edit them directly

Another example of encapsulation but this time on the navigation collection level is seen in eShopOnWeb with the use of IReadOnlyCollection.

We can see below that the _items collection is private so no potential consumer of the basket class can manipulate this collection directly and potentially bypass the business logic.

The Items collection on the other hand is exposed as an IReadOnlyCollection which acts as a in-synch (changes to the underlying collection are reflected in the IReadOnlyCollection) wrapper around the main _items collection.

Click on the image for a larger view in a new window…

One thought on “eShopOnWeb Architecture (7/16) – encapsulates navigation collections so consumers can’t edit them directly”

Leave a Reply

Your email address will not be published.