You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@event#Simplest event, just notify something happens, no provide extra information about the event (like why,how,when), no recolection of information from suscribers
@event#event with custom EventArgs, notify something happens and provides extra information (like why,how,when), no recolection of information from suscribers
@event#event with custom EventArgs, notify something happens provides extra information (like why,how,when), and it is capable of recolect info from its suscribers (this case implemeted as prevent)
#Use of a simple event (In this case implemented as a property change event)------------------------------------------------------------
239
-
person.NameChanged+=school.person_nameChanged#suscribe the school instance method to Namechanged event, (this method will be executed when the person's name change)
240
-
person.NameChanged+=callback_function#suscribe an extra simple function (this function will be executed when the person's name change)
241
-
person.Name="Susa"#Change the person name to trigger the event
239
+
person.name_changed+=school.person_name_changed#suscribe the school instance method to Namechanged event, (this method will be executed when the person's name change)
240
+
person.name_changed+=callback_function#suscribe an extra simple function (this function will be executed when the person's name change)
241
+
person.name="Susa"#Change the person name to trigger the event
#Use of a custom Eventargs with setter (allows to suscriber send information) in this case is implemented as a pre-event (triggers before something happens) this allows in this case cancel the Change of the person's location
258
-
person.LocationChanging+=school.person_locationchanging#add the suscriber
259
-
person.Location=13#change the location to trigger the event
260
-
person.Location=115#changing location again to trigger the event, suscriber has the capability to cancel the asignation of the new value
261
-
print("%s location at %s"%(person.Name, person.Location))#checking person's location it is (13,13) due suscriber cancel the asignation of the action thorugh the pre-event
258
+
person.location_changing+=school.person_location_changing#add the suscriber
259
+
person.location=13#change the location to trigger the event
260
+
person.location=115#changing location again to trigger the event, suscriber has the capability to cancel the asignation of the new value
261
+
print("%s location at %s"%(person.name, person.location))#checking person's location it is (13,13) due suscriber cancel the asignation of the action thorugh the pre-event
#suscribing a Delegate instead of passing a function/method directly (Due Delegates are callables) to an event, as well show case of using polimorfism, pasing an EventArgs parameter function to a LocationEventArgs parameter event
266
266
delegate=Delegate(callback_function) #create a delagate with one function with signature Callable[[object, EventArgs], None]
267
-
person.Moved+=delegate#suscribing a Callable[[object, EventArgs], None] to Callable[[object, MovedEventArgs], None] event
268
-
person.Location=1#changing location to trigger event
267
+
person.moved+=delegate#suscribing a Callable[[object, EventArgs], None] to Callable[[object, MovedEventArgs], None] event
268
+
person.location=1#changing location to trigger event
269
269
#in this case the event will provide an MovedEventArgs instance to the suscriber (the 'e' parameter), and suscriber handle the object as an EventArgs instance, by polimorfism is ok
#suscribing the methods internally on the class-------------------------------------------------------------------------------------------
273
-
school.Principal=person#Asign a principal to the school, the school will unsuscribe the old principal (if any) and suscribe to the new principal.Died event due it is of its interest know when its principal dies
274
-
person.Kill() #We kill the person :( (school will do its logic due its principal dies)
273
+
school.principal=person#Asign a principal to the school, the school will unsuscribe the old principal (if any) and suscribe to the new principal.died event due it is of its interest know when its principal dies
274
+
person.kill() #We kill the person :( (school will do its logic due its principal dies)
0 commit comments