Jan Pettersen Nytun, page no. 1
Syntax & Semantics UML - Java Jan Pettersen Nytun, page no. 1 - - PowerPoint PPT Presentation
Syntax & Semantics UML - Java Jan Pettersen Nytun, page no. 1 - - PowerPoint PPT Presentation
Syntax & Semantics UML - Java Jan Pettersen Nytun, page no. 1 Syntax From Wikipedia, the free encyclopedia: the syntax of a computer language is the set of rules that defines the combinations of symbols that are considered to be a
Syntax
Jan Pettersen Nytun, UIA, page 2
int age = 10; if (age >70){ System.out.println(“Can be retired!"); } else { System.out.println("Can not be retired!"); }
From Wikipedia, the free encyclopedia: “…the syntax of a computer language is the set of rules that
defines the combinations of symbols that are considered to be a correctly structured document or fragment in that language.” Java has a textual syntax. The If-sentence bellow is syntactically correct: First code word if followed by token ( , etc. …
Syntax Example
Jan Pettersen Nytun, UIA, page 3
EBNF is an example of a language for making a formal description
- f syntax.
E.g., defining integer with help of EBNF: digit <= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 integer <= [ + | - ] digit { digit } | | means alt alternative [] [] means op
- ptional
{} {} means repetit ition zero or
- r more tim
times
UML Has a Visual Syntax
(and also a textual one)
Jan Pettersen Nytun, UIA, page 4
If sentence in an activity diagram:
age = 10 Print: «Can be retired!» [age>70] [else] Print: «Can not be retired!»
A class is represented with the help of a rectangle:
Semantics
Jan Pettersen Nytun, UIA, page 5
The study of meanings. Used to differentiate the meaning of an instruction from its format. Semantics "provides the rules for interpreting the syntax which do not provide the meaning directly but constrains the possible interpretations of what is declared.“[1]
[1] Euzenat, Jerome. Ontology Matching. Springer-Verlag Berlin Heidelberg, 2007, p. 36
Jan Pettersen Nytun, UIA, page 6
age= 10
Print: «Can be retired!»
[age>70] [else] Print: «Can not be retired!»
Semantics of the if-sentence in english: If the boolean expression evaluates to true then execute what is between the following { and }...
The samantics of a branch is the «same as» the if sentence.
Here the symbol function as a merge (i.e., not an if)
int age = 10; if (age >70){ System.out.println(“Can be retired!"); } else { System.out.println("Can not be retired!"); }
Code Generation
Semantics of UML constructions expressed with Java expressions
Jan Pettersen Nytun, UIA, page 7
package Journal.model; public class Person { private String firstName; private String lastName; } package Journal.model; public class Patient extends Person{ private PatientFile has; } package Journal.model; public class PatientFile{ private java.util.List<PatientRecord> contains; private Patient concerns; }
8/3/2016 Introduction to Object-oriented Software Development, J.Pettersen Nytun page no. 8,
public class PatientFile{ private java.util.List<PatientRecord> contains;...
MagicDraw: UML Java
Operations Method
Jan Pettersen Nytun, UIA, page 9
public class Person { private String firstName; private String lastName; public String getName( ){ return null; } public void setName( String name ){ } }
Jan Pettersen Nytun, UIA, page 10
package Journal.controller; import Journal.model.PatientFile; public class JournalApp { private java.util.List<PatientFile> patientFiles; public static void main( String[] args ){ } }
MagicDraw - I Meny velg: Tools/Generate Code/Java
Jan Pettersen Nytun, UIA, page 11
Software Engineering
- Ref. : http://developeriq.in/articles/2013/dec/24/the-myth-of-software-reengineering/
Jan Pettersen Nytun, UIA, page 12