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

Problem of inheritance in agents #49

Closed
gbasso opened this issue Mar 26, 2014 · 6 comments
Closed

Problem of inheritance in agents #49

gbasso opened this issue Mar 26, 2014 · 6 comments
Assignees
Labels
Milestone

Comments

@gbasso
Copy link

gbasso commented Mar 26, 2014

This is the same problem as events and capacities, but I din't see it for agents.

With:

agent MyAgent1
{}

agent MyAgent2 extends MyAgent1 // no error
{}

The following Java code is generated:

public class MyAgent2 extends Agent {
@gallandarakhneorg
Copy link
Member

The generation of the correct extend type is easy to apply (done in gallandarakhneorg/sarl).
But, there is additional points to focus on if we introduce the extension mechanism for agents:

  • How to call the super's implementation for a def.
  • How to call the super's implementation for an event.

For illustrating, let take the following example:

agent AbstractAgent {

    uses Lifecycle

    on Initialize {
        System.out.println("Hello World in the super agent!")
    }

    def sayGoodBye {
        System.out.println("Goodbye World!")
    }

}

agent HelloChildAgent extends AbstractAgent{

    uses Schedules

    on Initialize {
        System.out.println("Hello World in the child agent!")
        in(2000)[killMe]
    } 

    def sayGoodBye {
        super.sayGoodBye()
    }

    on Destroy {
        sayGoodBye
    }
}

@gallandarakhneorg
Copy link
Member

The FAQ or the tutorials should explain that calling an override function is possible, but not an event handler.

@gallandarakhneorg
Copy link
Member

There is a problem to access to the inherited attributes.

@ngaud
Copy link
Member

ngaud commented Apr 3, 2014

The idea here is to change the visibility of getter/setter methods to "protected" to enable an access to parent field from a sub-class.

@gallandarakhneorg
Copy link
Member

Consider the SARL code:

agent A {
   var thevar = false
}

It is not possible to generate the setter function due to a Xtext limitation. Indeed, the generated setter may be:

public void setThevar(<<INFERENCED TYPE>> thevar) {
  this.thevar = thevar;
}

Unfortunately, for generating the method setThevar Xtext needs to kwow all the properties of the formal parameters. But, the inferred type cannot be determine because the inferring engine is not reflexive. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=408323.

@gallandarakhneorg
Copy link
Member

The only way to provide access to the attributes from the subclasses of agents is to make protected the attributes. The getter/setter becomes not more required.

gallandarakhneorg added a commit that referenced this issue May 15, 2014
…ssue #49),

the agent's variables are generated as protected java fields.
gallandarakhneorg added a commit to janus-project/janusproject that referenced this issue May 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants