Implicit and explicit trusting.
If you have any requirement where a class has to share some
of its information (not all). With an external system, or we can say a condition where we have to violate encapsulation. Then we will use two
different methods to activate it –
1. Implicit trusting –
Share your class’s private information with an
object which is created by your class only. Or object which can
be created by your class in the future. For example, iterator design pattern. In
many cases, we destroy the object once the job is done. So the life cycle of the
object is in your hand. That's why we call it implicit trusting. As you have
some kind of control over it, and you are the owner of that object. Destroy it
whenever you feel the work gets completed.
2. Explicit trusting –
Share class’s private information with
trusted object. Here object is not created by your class. But you have the
prior knowledge of object which is requesting your class to know it's internal state. It’s up to your class; to allow them or not.
For example, visitor design pattern. Where you know the signature of requesting
object. You can very well decline to share information about your class's internal state. If you see the object's signature is not proper. As your class is not open to all other classes. It will act like a black box, for others.
Thanks for reading it. To learn more about design patterns and basic design principles, please see my web page.
Comments
Post a Comment