Events have signatures to obey. We can attach two or more functions in an Event. All of them have to read the same type of parameters. These events use object types events. M2000 also have light events, which are controlled by named groups, defined WithEvents, and always call one function (with no signature like the objects events). We use one light event in Mediator group.
// update code, now x in ConcreteColleague is a private member.
// also the event handlers do1() and do2() in ConcreteMediator now are private members.
class Colleague {
module takethis (ev1, ev2) {
error "not implemented yet"
}
}
class ConcreteColleague as Colleague {
private:
x=2000
public:
module takethis (ev1, ev2){
call event ev1, 100+.x
call event ev2, &.x
}
}
class Mediator {
module mediate {
error "not implemented yet"
}
}
\\ this ConcreteMediator works with Colleague objects
class ConcreteMediator as Mediator {
event "finished"
myacc=0
module work1 (&that as Colleague) {
that.takethis .one, .two
}
event one {
read x
}
event two {
read &x
}
Private:
Function do1(New n) {
Print "n=";n
.myacc+=n
}
Function do2(New &n) {
n+=20000
}
Public:
module Mediate (&C as Colleague) {
do
.work1 &C
Until .myacc>=2400
call event "finished"
}
class:
Module ConcreteMediator (&m()) {
event .one new &.do1(), m()
event .two new &.do2()
}
}
acc=0
Function AnyName {
Read New k
print "from AnyName:", k
acc+=k
}
concreteColleague=ConcreteColleague()
Group WithEvents Mediator=ConcreteMediator(Lazy$(&Anyname()))
Function Mediator_finished {
Print "Finished ", acc
}
Mediator.Mediate &concreteColleague
Print Mediator.myacc=24200
Print acc=24200
module takethis (ev1, ev2) {
error "not implemented yet"
}
}
class ConcreteColleague as Colleague {
private:
x=2000
public:
module takethis (ev1, ev2){
call event ev1, 100+.x
call event ev2, &.x
}
}
class Mediator {
module mediate {
error "not implemented yet"
}
}
\\ this ConcreteMediator works with Colleague objects
class ConcreteMediator as Mediator {
event "finished"
myacc=0
module work1 (&that as Colleague) {
that.takethis .one, .two
}
event one {
read x
}
event two {
read &x
}
Private:
Function do1(New n) {
Print "n=";n
.myacc+=n
}
Function do2(New &n) {
n+=20000
}
Public:
module Mediate (&C as Colleague) {
do
.work1 &C
Until .myacc>=2400
call event "finished"
}
class:
Module ConcreteMediator (&m()) {
event .one new &.do1(), m()
event .two new &.do2()
}
}
acc=0
Function AnyName {
Read New k
print "from AnyName:", k
acc+=k
}
concreteColleague=ConcreteColleague()
Group WithEvents Mediator=ConcreteMediator(Lazy$(&Anyname()))
Function Mediator_finished {
Print "Finished ", acc
}
Mediator.Mediate &concreteColleague
Print Mediator.myacc=24200
Print acc=24200
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου
You can feel free to write any suggestion, or idea on the subject.