I spent yesterday playing around with trygve environment and implemented a small breakout clone:
--
You received this message because you are subscribed to the Google Groups "object-composition" group.
To unsubscribe from this group and stop receiving emails from it, send an email to object-composit...@googlegroups.com.
To post to this group, send email to object-co...@googlegroups.com.
Visit this group at https://groups.google.com/group/object-composition.
For more options, visit https://groups.google.com/d/optout.
The essence of object orientation is
that objects collaborate to achieve a
goal.
Trygve Reenskaug mailto: try...@ifi.uio.no
Morgedalsvn.
5A http://folk.uio.no/trygver/
N-0378
Oslo http://fullOO.info
Norway Tel:
(+47) 22 49 57 27
Nice. What about two independent balls with different colors?
Den 26/04/2016 kl. 14.13 skrev Egon Elbre <egon...@gmail.com>:
I spent yesterday playing around with trygve environment and implemented a small breakout clone:
….
Thanks for this great example Egon! I've only skimmed the code so
far, but one thing I noticed is that you have 3 contexts that have
no roles: Display, State, Breakout. Could you explain the reason
for that? Is it because there are no role methods? The idea of a
Context with no roles seems a little strange to me, especially in
a language that also provides classes.
Thanks for this great example Egon! I've only skimmed the code so far, but one thing I noticed is that you have 3 contexts that have no roles: Display, State, Breakout. Could you explain the reason for that? Is it because there are no role methods?
private Panel panel_; private Frame frame_; private Mouse mouse_;
role Display requires Display; role World requires World;
role Handler { public void collide(Entity A, Entity B){ onCollision(A, B); } } requires { public void onCollision(Entity A, Entity B); }
role Handler requires CollisionHandler
The idea of a Context with no roles seems a little strange to me, especially in a language that also provides classes.
Den 26/04/2016 kl. 15.06 skrev Trygve Reenskaug <try...@ifi.uio.no>:The diagnosticline 138: NONCOMPLIANT: Trying to enact object script `setBackground(Color)' without using the interface of the Role it is playing: `ARENA'.The roleScript Ball::draw() says on line 138ARENA.setBackground(Color.blue);A role is the name of an object. We used to say that a role is the object and understands the hundreds of messages understood by it. In Trygve, this large interface is filtered by the requires clause. I like this innovation because it gives me control over my use of the object. The interface called required is the subset of the object's interface that is visible through the role. This is an abstraction interface; the correctness of its implementation has to be taken on trust. The role scripts define what you have called the role interface. Its members are compactions of scripts visible within the context. A role understands the combination of the two. This combined interface is what the programmer sees. Yesterday, I would have called it the role role's interface, but this term can't mean both the local and the combined interfaces. So I think the NONCOMPLAINT is superfluous since `setBackground(Color)' is in the interface explicitly defined in the requires clause.I know, but it’s good to hear that this is your dominant perspective.What’s the difference between the requires clause and your proposed using clause?The requires clause gives control over what parts of the object interface are available to the Role. The Role interface gives control over what parts of the object (the Role methods) are available to other Roles. The using clause is an alias that selectively clones parts of the former for inclusion in the latter.I’ve found it a great inconvenience to work around this NONCOMPLIANT message: it leads to bad renaming of things that shouldn’t have to be renamed merely for the sake of aliasing. The using directive solves that. It also shows that the programmer has made a conscious decision to expose parts of the object interface to other Roles. Right now there is no way to distinguish between those two cases (making an instance method available to the Role it is playing versus making it visible to other Roles in the Context).I like to be able to reason about the use case through the Role logic alone. If instance methods return then it’s easy to believe in that trust boundary between the object and the Role. But if a Role’s requires list means that the instance method is published to the entire Context it takes away my ability to reason about the Role / instance interface locally. I have to reason about the instance methods of all objects across the entire Context. It’s harder to envision the execution contextualisation that could be a basis for that trust, as things get pretty complicated at the Context level. So I issue a warning. The using directive is a pragma in disguise that basically would turn off the warning — it’s a way for the programmer to tell the compiler “I know what I’m doing.”Given this rationale, does it change your opinion? I’m among the first in line to get rid of the annoyance of this warning. But I think the issue is a bit more finessed than you describe it and I want to ensure we’re not opening the door to bad practices by getting rid of it.
Den 28/04/2016 kl. 14.21 skrev Egon Elbre <egon...@gmail.com>:...
The semantics of "you cannot call directly a role player method" and not being able to define a type as a requirement, made it difficult to make them into proper roles, so I opted for a "private member" instead.role Display requires Display; role World requires World;Similarly I would have wanted to directly call the role-player methods e.g. instead ofrole Handler { public void collide(Entity A, Entity B){ onCollision(A, B); } } requires { public void onCollision(Entity A, Entity B); }write:role Handler requires CollisionHandlerNote: I'm not necessarily saying what I wanted to do was a good idea, but rather what seemed appropriate at the time and they may have significant problems. And, I may have missed some of the features that trygve has.The idea of a Context with no roles seems a little strange to me, especially in a language that also provides classes.
In this code, I used classes as "data records"/"structs" and have single purpose, and the context as where things interact and have more complex logic.+ Egon
...
I like to be able to reason about the use case through the Role logic alone. If instance methods return then it’s easy to believe in that trust boundary between the object and the Role. But if a Role’s requires list means that the instance method is published to the entire Context it takes away my ability to reason about the Role / instance interface locally. I have to reason about the instance methods of all objects across the entire Context. It’s harder to envision the execution contextualisation that could be a basis for that trust, as things get pretty complicated at the Context level. So I issue a warning. The using directive is a pragma in disguise that basically would turn off the warning — it’s a way for the programmer to tell the compiler “I know what I’m doing.”