In my C# software, I have a number of drawing tools. Each tool has its own class with a common interface. E.g. “Draw rectangle”.
Now, many of these tools need to read data from my main window in order to perform their tasks. However, I don’t want these tools to be coupled with my MainForm class. Obviously, there is a need for a better design. Which design pattern is suitable for the task?
Q: How can class X read arbitrary information from class Y, without coupling the two classes?
You want to abstract
Yinto an interface designed specifically just to allow retrieving the kind of informationXneeds.At the same time, you don’t want to leak into the interface the specifics of a particular implementation you may have in mind (for example your main window).