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.
Follow for daily .NET posts | Microsoft MVP | Senior Software Engineer
3 年Part 1 - uses marker interfaces to communicate intent and enforce design constraints https://lnkd.in/d-PWGS3J Part 2 - uses Value Objects to model domain concepts without identity https://lnkd.in/dX_eFuti Part 3 - uses custom exceptions to more explicitly express what has gone wrong https://lnkd.in/dHpp2-E3 Part 4 - uses the MediatR library to keep controllers thin https://lnkd.in/dX7VfD6i Part 5 - makes regular use of Guard Clauses https://lnkd.in/d--hmXz5 Part 6 - uses private setters and non default constructors to support encapsulation which helps keep the model valid https://lnkd.in/dEwY_iep Part 7 - encapsulates navigation collections so consumers can’t edit them directly https://lnkd.in/dk5DXRKh Part 8 - uses in memory caching to avoid sending unnecessary queries to the DB https://lnkd.in/dg_Y5qUx Part 9 - uses the Aggregate root pattern to ensure child objects are not manipulated out of context https://lnkd.in/d46XBjeC Part 10 - has unit tests which test very low level implementation details https://lnkd.in/dd69BEpU Part 11 - uses AutoMapper https://lnkd.in/deeCwcBa Part 12 - uses the repository and specification pattern https://lnkd.in/dd6RiDUy Part 13 - has some single implementation interfaces https://lnkd.in/drkhgk8T Part 14 - uses parameterized tests https://lnkd.in/dgqTTP4F Part 15 - has a really nice example of the Interface Segregation Principle https://lnkd.in/dgkn5fqx Part 16 - uses clean architecture https://lnkd.in/d-bS24cY