Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static variable in Events #426

Closed
GlennCich opened this issue Jun 23, 2016 · 2 comments
Closed

Static variable in Events #426

GlennCich opened this issue Jun 23, 2016 · 2 comments

Comments

@GlennCich
Copy link

GlennCich commented Jun 23, 2016

I need a unique identifier for a specific event. A way to do this is by creating a static variable.

event e 
{
    static var uniqueIdCounter : long
    val uniqueId : long
    new()
    {
        increaseUniqueIdCounter
        uniqueId = uniqueIdCounter
    }

    def increaseUniqueIdCounter()
    {
        uniqueIdCounter++
    }
}

However, SARL doesn't seem to provide the static key word in an event.

@gallandarakhneorg
Copy link
Member

Currently, the static keyword is not allowed for attributes (for backward compatibility with the old SARL syntax) .
We should discuss about its support in agents, behaviors, and skills.

Regarding events, we must be careful. Indeed, they have a special position in the language: they are data objects exchanged by agents. Consequently, we must ensure that it is possible to serialize/deserialize (or any other mechanism) static attributes. It is more related to the capabilities of the Java language in this case.

@gallandarakhneorg
Copy link
Member

Static field will not be enable in events. The factory design pattern should be used.
We will provide in the documentation a tutorial for creating events with a factory according to the case explained in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants