-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Let us suppose we want to protect CachedValue's such that only the objects allowed to alter them can alter them.
using FingerPrint = void*;
constexpr UniversalFingerPrint = nullptr;DataAccessor has private member FingerPrint FingerPrint_; created in constructor.
CachedValue has a private member FingerPrint FingerPrint_; handed in at construction.
Both classes have a const protected getter
protected:
const FingerPrint fingerPrint() const
{ return FingerPrint_; }And now we alter:
CachedValue::setValue( ....., const FingerPrint& fp)
{
if (fb != fingerPrint()) throw;
...
}In this way, DataAccessor decides either
- It gives its thumb print to the
CachedValueit creates, so that only it can callsetValueon it. - Or it gives UniversalFingerPrint to the
CachedValueas a finger print, meaning anyone can callsetValueon it.
This could also all possibly be restructured such that we have a compile time error instead of a runtime error.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels