Using delegate to avoid circular dependency

I personally didn’t like that our ServerRow knew about the MainMenu. This would create a circular dependency! Plus, I think this row should really be self contain and reusable in different context.

For those reason, instead of giving the ServerRow a pointer to the MainMenu, I hadded a delegate in the row. The main menu can then simply bind itself on each row and get’s warn when a row is selected!

ServerRow:
image

image

MainMenu

2 Likes

This is a really nice solution. Thanks for sharing.

As it happens, getting a reference to the parent isn’t a terrible solution and quite a common one. Using a pure abstract to expose methods would be a better solution than referring to the menu by type directly, and would make it easier to swap out references.

Privacy & Terms