[otj-users] How a role captures context from a base object?
Miguel Pessoa Monteiro
mmonteiro at di.fct.unl.pt
Wed Jul 2 15:38:48 CEST 2008
Greetings to all,
I'm taking my first steps on OT/J, using OT/J 1.2.0M3 on top of eclipse 3.4.0. I
hope you can bear with some beginner questions.
To keep things focused, I'll stick to one question per post. This one is
straightforward: how does a role obtain state from a base object?
I tried the following simple example. I understand that using keyword 'base' is not
the way, but it is not clear to me what is the right way to do it.
Note that method BaseObject.trigger() is just a way to "call" the team from main, as
I'm also uncertain of a suitable way to do that too. I'll come to that in some other
post.
I looked into the language definition before writing this post, but I may have
missed the relevant section. If there is a section that directly answers it, just
point it to me.
Thanks,
Miguel P. Monteiro
----------------------------------------------------------------------------
public class BaseObject {
private int _internalNumber = 23;
public int value() {
return _internalNumber;
}
public void trigger() {
System.out.println("trigger");
}
}
public team class Team {
public class Role playedBy BaseObject {
public void doSomething() {
//Syntax error on token "base", invalid Expression:
System.out.println("BlackBox base object: " + base);
}
void doSomething() <- before void trigger();
}
}
public class Main {
public static void main(String[] args) {
Team teamObject = new Team();
teamObject.activate();
BaseObject baseObject = new BaseObject();
baseObject.trigger();
}
}
----------------------------------------------------------------------------
--
Miguel P. Monteiro | cell phone +351 96 700 35 45
Departamento de Informatica | Phone +351 21 294 8536 ext. 10708
Faculdade Ciencias e Tecnol.| Fax: +351 21 294 8541
Universidade Nova de Lisboa | URL: http://ctp.di.fct.unl.pt/~mpm
2829-516 Caparica, PORTUGAL | e-mail: mmonteiro [at] di fct unl pt
More information about the otj-users
mailing list