In my code, I've got two interfaces, let's say `IOpenable` and `IExaminable`. `IOpenable` allows the user to `Open` or `Close` the object, and `IExaminable` allows the user to `Examine` the object.
Now, we have some sort of `Tile` structure which contains objects which adhere to the following: Not all objects are openable, not all objects are examinable, some are both.
When the user right clicks a `Tile` in-map, I want to populate some sort of list with the possible targets and their varied functionalities.
As a concrete example, let's say that a `Book` is examinable and openable, whereas a `Card` is just examinable. When I right click, I wanted to make it so that I can navigate through Open -> Book or Examine -> [Card | Book].
At the moment, I'm essentially copy/pasting code, where I assess each time if any object is `IOpenable` and add it to a list of `Open` targets. Then I do the same for `Close`, then `IExaminable` with `Examine`. I'm tying the functionality of the button to a delegate e.g. [Open -> Book] would have the functionality
delegate
{
lockedInteractable.Open();
}
The problem with this is, I'm reusing the same code every single time, just changing which interface we're looking for (e.g. changing `IOpenable` to `IExaminable`) and changing the function in the delegate (e.g. `.Open()` to `.Examine()` or whatever).
Is there a more efficient way to do this? Is this simply a product of my bad code practice in making things implement IOpenable and IExaminable like that?