Facilitating Communication Between Objects
Explore how to facilitate communication between objects using design patterns in C#. Understand the Mediator pattern that centralizes interaction and the Observer pattern supporting dynamic event subscription. This lesson helps you apply these patterns to keep code modular, maintainable, and compliant with design principles.
Problem statement
Let’s imagine that we have a container object that contains other objects of various types. To make it clearer, imagine that the container object is the background of a user interface, while other objects, such as text boxes, buttons, labels, etc., are its components.
Certain objects need to emit certain events that should be able to affect other objects. For example, clicking a particular button should be able to change the text on specific labels.
The last thing we want to do in this situation is to connect the components directly to each other. If we do that, our code becomes excessively complex. It’s especially true when we have many elements inside the ...