C # class question

I have a singleton Winform class that contains several buttons. Button events are handled and controlled in separate classes that have a link / instance of the singleton winform class. Thus, it is obvious that when the user clicks the buttons, the tasks associated with them are processed in the corresponding classes.

My question is that the classes that control the events are fully encapsulated, which means that no methods are required for their operation. The only thing they need is an event that should be fired, and the tasks are completed. Where should I create objects for these classes? Should I just create objects in winform at boot time? No additional interactions with objects are required; they just need an instance to observe button click events. I hope I have explained this clearly enough.

Thanks.

+4
source share
2 answers

If you create a real observer model, the association belongs to the creator of the control.

If you just click logic on individual classes, then this is more of a delegate template, and it should be the control to which the links belong.

+1
source

Yes, I think the Load form event is the logical place to create these objects. Or perhaps a constructor.

You cannot create them before the form has been built, because then there will be no buttons. And you also should not create it later, because then you can skip some events. Thus, the form of your own events is the best place to create them. Or at least bind them to events. Are these classes the same?

+1
source

Source: https://habr.com/ru/post/1334909/


All Articles