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
Copy file name to clipboardExpand all lines: README.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,7 +72,7 @@ For objective 2, the module was architected thinking in how another EOP language
72
72
73
73
2. delegates are not commonly exposed publicly, for security reasons. Just as fields/attributes in a class have to be encapsulated, so do delegates. The way to encapsulate them is with events. Fields/attributes are to properties as delegates are to events.
74
74
75
-
3. Properties encapsulate fields/attributes using two methods: "get" and "set", which define the logic of how data should be GET and SET out of the object, in C# events encapsulate delegates with 2 methods as well called "add" and "remove", which define the logic of how functions/subscribers should be added or removed out of the delegate.
75
+
3. Properties encapsulate fields/attributes using two methods: "getter" and "setter", which define the logic of how data should be GET and SET out of the object, in C# events encapsulate delegates with 2 methods as well called "adder" and "remover", which define the logic of how functions/subscribers should be added or removed out of the delegate.
76
76
77
77
78
78
## Installation
@@ -376,7 +376,7 @@ Below this text, the use cases and explanation about the events are shown, pleas
376
376
def name_changed(self,value)->None: # This example doesn't contain the parameter annotations for simplicity because it is the first example, however (as the document will explain in the summary of simple events), it is really important to place the event annotations. (There is a link at the end of this code block to go to the explanation)
377
377
self._name_changed += value
378
378
379
-
@name_changed.remove
379
+
@name_changed.remover
380
380
def name_changed(self,value)->None: # Annotations are not included for simplicity because it is the first example
381
381
self._name_changed -= value
382
382
@@ -408,21 +408,21 @@ To implement a *simple event* the first thing you have to do is create a variabl
408
408
self._name_changed = Delegate() # it can be viewed as a "To do list"
409
409
```
410
410
411
-
As you might notice the variable that is going to store the subscribers is a Delegate and the name starts with'_' to "protect" the attribute. Expose the attribute "publicly"isnot a good practice, because other parts of the code can manipulate the attribute wrongly or get/set information in a way that was not mean to. To fix this, we can define 2 methods to encapsulate the delegate (add/remove methods), Through these 2 methods the other objects in the code can subscribe/unsubscribe (add/remove) callables to our delegate.
411
+
As you might notice the variable that is going to store the subscribers is a Delegate and the name starts with'_' to "protect" the attribute. Expose the attribute "publicly"isnot a good practice, because other parts of the code can manipulate the attribute wrongly or get/set information in a way that was not mean to. To fix this, we can define 2 methods to encapsulate the delegate (adder/remover methods), Through these 2 methods the other objects in the code can subscribe/unsubscribe (add/remove) callables to our delegate.
412
412
413
413
```Python
414
414
@event
415
415
def name_changed(self,value)->None:
416
416
self._name_changed += value # add the new callable to the attribute with a delegate
417
417
418
-
@name_changed.remove
418
+
@name_changed.remover
419
419
def name_changed(self,value)->None:
420
420
self._name_changed -= value # remove the callable to the attribute with a delegate
421
421
```
422
422
423
-
Code above implements add/remove logic to the delegate. Function below *@event* decorator defines the logic for the *add*or how a callable should be added to our "To do list". Function below *@name_changed.remove* defines the logic for the *remove*or how a callable should be removed from the delegate
423
+
Code above implements add/remove logic to the delegate. Function below *@event* decorator defines the logic for the *add*or how a callable should be added to our "To do list". Function below *@name_changed.remover* defines the logic for the *remover*or how a callable should be removed from the delegate
424
424
425
-
Notice the functions HAVE to be named exactly with the same name, andif an *@event*is defined you **must** implement *@IDENTIFIER.remove*or the code will throw a traceback, this is to protect the integrity of the code and provide instructions about how to add AND remove a callable.
425
+
Notice the functions HAVE to be named exactly with the same name, andif an *@event*is defined you **must** implement *@IDENTIFIER.remover*or the code will throw a traceback, this is to protect the integrity of the code and provide instructions about how to add AND remove a callable.
426
426
427
427
The callable to be added/removed will be passed through the "value" parameter. Notice in this example "value" parameter doesn't have any type annotation, this is only to keep this first example "simple/readable" at first sight, however it is **HIGHLY RECOMMENDED** annotate the type as the following examples on this document (Events with arguments or Events with modifiable arguments examples contain these annnotations), due this is the way to indicate clearly what is the signature expected from the event to their subscribers (callables). [Link to event annotation convention explanation](#event-annotation-convention)
428
428
@@ -499,7 +499,7 @@ The next snipped code shows and example of how the *simple events* should be imp
@@ -516,9 +516,9 @@ def person_name_changed(sender:object,e:EventArgs)->None: #function to be execut
516
516
print("person change its name to %s"% sender.name)
517
517
518
518
person= Person("Juan") #creates a person
519
-
person.name_changed += person_name_changed # we add 'person_name_changed' (subscriber) to event name_changed of 'person', this line will execute function under @event decorator (add function)
519
+
person.name_changed += person_name_changed # we add 'person_name_changed' (subscriber) to event name_changed of 'person', this line will execute function under @event decorator (adder function)
520
520
person.name ="Carlos"# change the name to trigger the event (this will execute 'person_name_changed')
521
-
person.name_changed -= person_name_changed #unsubcribe the function, this line will execute function under @name_changed.remove decorator (remove function)
521
+
person.name_changed -= person_name_changed #unsubcribe the function, this line will execute function under @name_changed.remover decorator (remover function)
522
522
person.name ="Something"# change the name again to prove 'person_name_changed' is not executed anymore
523
523
```
524
524
@@ -568,7 +568,7 @@ person.name = "Something" # change the name again to prove 'person_name_changed'
raiseAttributeError("add function '%s'and remove function '%s' name missmatch, both members must have same name"% (fadd.__name__,self._fremove.__name__))
170
+
raiseAttributeError("adder function '%s'and remover function '%s' name missmatch, both members must have same name"% (fadd.__name__,self._fremove.__name__))
raiseAttributeError("remove function '%s'and add function '%s' name missmatch, both members must have same name"% (fremove.__name__,self._fadd.__name__))
185
+
raiseAttributeError("remover function '%s'and adder function '%s' name missmatch, both members must have same name"% (fremove.__name__,self._fadd.__name__))
description="python# (python sharp) is a module created to add EOP (event oriented programing) into python in the most native feeling, easy sintax way possible. Based on C# event implementation structure", # Short description
0 commit comments