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

No need for default implementations of interface while they are implemented by state machines #923

Closed
vahdat-ab opened this Issue Nov 28, 2016 · 8 comments

Comments

Projects
None yet
4 participants
@vahdat-ab
Copy link
Member

commented Nov 28, 2016

By default in Umple, abstract methods of interfaces are automatically implemented inside classes when there are not implementation for them. This helps to have a rapid development process (to have an executable system). However, when there are implemented by events of state machines, no need to generate them as well. This results in having two methods with the same signature. Consider the following example:

interface Logger {
	boolean connect();
	boolean disconnect();
	boolean write(String Data);
}

class FileLogger{
	isA Logger;
	internal fileName;
	status{
		disconnected{
			connect -> connected;
		}
		connected{
			disconnect -> disconnected;
			write(String) -> connected;
		}	
	}
}

The methods of interface Logger is implemented by events of state machine status, so there is no need to have default implementations for them. The following snippet is part of the generated code.

  public boolean connect()
  {
    boolean wasEventProcessed = false;
    
    Status aStatus = status;
    switch (aStatus)
    {
      case disconnected:
        setStatus(Status.connected);
        wasEventProcessed = true;
        break;
      default:
        // Other states do respond to this event
    }

    return wasEventProcessed;
  }

  @Override
  public boolean connect(){
          return false;
  }

@vahdat-ab

This comment has been minimized.

Copy link
Member Author

commented Nov 28, 2016

This is somehow related to the issue #663

@jblang94

This comment has been minimized.

Copy link
Contributor

commented Jan 21, 2017

Identified the issue on line 38 in UmpleToJava/UmpleTLTemplates/class_MethodDeclaration.ump
String override = aMethod.getIsImplemented() ? " @Override\n" : "";
There are no additional checks to see if aMethod matches an event name in a state machine.

Next steps:

  1. Create test cases such as the example above to ensure that the default implementations of the interface are not added in the case where a state machine implements the interface.
  2. Add fix to PHP and Java code generation
  3. Re-run my test cases and ensure they pass
@jblang94

This comment has been minimized.

Copy link
Contributor

commented Jan 23, 2017

@vahdat-ab
I am wondering, in the case where the state machine's events implement the interface's methods, if they should be prefixed with "@override"?
ex.
public boolean connect()
to

@Override
public boolean connect()

The generated Java code compiles for either case. I believe if I am to include this in the fix, I will need to modify "state_machine_Event.ump" which is in the UmpleTLTemplates directory for both UmpleToJava and UmpleToPhp.

@Nava2

This comment has been minimized.

Copy link
Member

commented Jan 23, 2017

(Good Java practice says that you should use @Override on any method that is implemented from an interface or super class)

@jblang94

This comment has been minimized.

Copy link
Contributor

commented Jan 24, 2017

Thanks @Nava2 !

jblang94 added a commit to jblang94/umple that referenced this issue Jan 27, 2017

jblang94 added a commit to jblang94/umple that referenced this issue Jan 27, 2017

@jblang94 jblang94 referenced this issue Jan 27, 2017

Merged

Fix issue 923 #978

@jblang94

This comment has been minimized.

Copy link
Contributor

commented Jan 27, 2017

@vahdat-ab I noticed, with the most recent version of the Umple compiler from "master", that the following line in your example
write(String) -> connected;
gets generated as
public boolean write(String String) in Java

Is this just an error in your example, or is Umple supposed to generate default parameter names when one isn't specified? (i.e. public boolean write(String s) There wasn't a specific example of this on the User Manual page http://cruise.eecs.uottawa.ca/umple/MethodDefinition.html

@TimLethbridge

This comment has been minimized.

Copy link
Member

commented Jan 27, 2017

This looks like an error in the example. the argument to write is supposed to be a variable name, not a type when it is being specified as an event in a state machine.

@jblang94

This comment has been minimized.

Copy link
Contributor

commented Jan 27, 2017

@TimLethbridge Thank you for the clarification

@vahdat-ab vahdat-ab closed this Jan 27, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.