Model-based Software Engineering (02341, Spring 2017) Ekkart Kindler

Similar documents
Teneo: Integrating EMF & EclipseLink

Programming II (CS300)

Programming II (CS300)

Recitation 3 Class and Objects

COMP200 - Object Oriented Programming: Test One Duration - 60 minutes

CSE115 Introduction to Computer Science I Coding Exercise #7 Retrospective Fall 2017

Notes on Chapter Three

Readings for This Lecture

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

Announcements for the Class

Model handling with EMF

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

Eclipse Modeling Framework (EMF) Paweł Żalejko

CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

CISC-124. Dog.java looks like this. I have added some explanatory comments in the code, and more explanation after the code listing.

COMP 401 Spring 2013 Midterm 1

CS 302 Week 9. Jim Williams

Advanced Topics in Software Engineering (02265) Ekkart Kindler

Software Engineering 2 A practical course in software engineering. Ekkart Kindler

Advanced MEIC. (Lesson #18)

Java Classes. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar

CMP-326 Total 120 Points Final Fall 2012

Model-based Software Engineering (02341, spring 2017) Ekkart Kindler

AbstractCommand, AbstractEnumerator, AbstractOverrideableCommand, AddCommand, AbstractTreeIterator, Adapter, EAnnotation.

Distributed Systems Recitation 1. Tamim Jabban

CS 1331 Exam 1 ANSWER KEY

COMP 401 Spring 2014 Midterm 1

1B1b Classes in Java Part I

Exam 1 - (20 points)

Introduction to Programming Using Java (98-388)

(a) Write the signature (visibility, name, parameters, types) of the method(s) required

University of Massachusetts Amherst, Electrical and Computer Engineering

Model-based Software Engineering (02341, spring 2017) Ekkart Kindler

Distributed Systems Recitation 1. Tamim Jabban

Model-based Software Engineering (02341, spring 2017) Ekkart Kindler

(Meta)Models between MetaEdit+

What is an Iterator? An iterator is an abstract data type that allows us to iterate through the elements of a collection one by one

C08: Inheritance and Polymorphism

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

COMP 401: THE DUAL ROLE OF A CLASS. Instructor: Prasun Dewan (FB 150,

Programming II (CS300)

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Domain-Driven Design Activity

Getter and Setter Methods

Generating/Updating code from whole project

Java Classes, Inheritance, and Interfaces

Example: Fibonacci Numbers

EMF course - PACT. Etienne Borde

Software Engineering 2 A practical course in software engineering. Ekkart Kindler

Lecture 10. Overriding & Casting About

#archap 1 * LectureNotes. +LectureNotes(in title : String, in n : int, in coursename : String)

CSC Java Programming, Fall Java Data Types and Control Constructs

RAIK 183H Examination 2 Solution. November 10, 2014

Employee class: Attributes: Methods:

PROGRAMMING FUNDAMENTALS

Recursion 1. Recursion is the process of defining something in terms of itself.

Java Persistence API (JPA) Entities

What is it? CMSC 433 Programming Language Technologies and Paradigms Spring Approach 1. Disadvantage of Approach 1

Algorithmic Thinking and Structured Programming (in Greenfoot) Teachers: Renske Smetsers-Weeda Sjaak Smetsers

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External

Overview of Eclipse Lectures. Module Road Map

Technology Tutorial. - Details and Advanced Concepts - Patrick Könemann Software Engineering 2 (02162)

COMP Information Hiding and Encapsulation. Yi Hong June 03, 2015

CMSC131. Creating a Datatype Class Continued Exploration of Memory Model. Reminders

CMPSCI 187: Programming With Data Structures. Lecture 6: The StringLog ADT David Mix Barrington 17 September 2012

CIT Special final examination

Objects and Iterators

COMP 401 Spring 2013 Midterm 2

Modif Documentation. Refactoring User Guide

1- Differentiate between extends and implements keywords in java? 2- What is wrong with this code:

Topic 10. Abstract Classes. I prefer Agassiz in the abstract, rather than in the concrete.

2/26/2017. DataFrame. The input data can be queried by using

Software and Programming 1

What is Wazaabi 2.0? Declarative UI framework. based on. live EMF model(s)

Model-based Software Engineering (02341, Spring 2017) Ekkart Kindler

Tiger EMF Model Transformation Framework (EMT)

INTRODUCTION TO EMF. Creating Model using EMF. Our Domain model used to showcase this use case is as shown below in fig.1

Software Engineering 2 A practical course in software engineering. Ekkart Kindler

Announcement. Agenda 7/31/2008. Polymorphism, Dynamic Binding and Interface. The class will continue on Tuesday, 12 th August

Classes Classes 2 / 35

Lecture 07: Object Encapsulation & References AITI Nigeria Summer 2012 University of Lagos.

COMP-202: Foundations of Programming. Lecture 26: Review; Wrap-Up Jackie Cheung, Winter 2016

APCS Semester #1 Final Exam Practice Problems

CSCE145 Test 2-Review 03/29/2015 Hongkai Yu

Final Exam COMP 401 Fall 2014

CMSC 433 Programming Language Technologies and Paradigms. Spring 2013

Author: Sascha Wolski Sebastian Hennebrueder Tutorials for Struts, EJB, xdoclet and eclipse.

CSE 331 Final Exam 3/12/12

The Object Class. java.lang.object. Important Methods In Object. Mark Allen Weiss Copyright 2000

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.

Singleton Pattern Creational

CS100J Prelim I, 29 Sept. 2003

Model-based Software Engineering (02341, spring 2016) Ekkart Kindler

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

The epnk: An extensible Petri net tool for PNML. Ekkart Kindler

COMP 401 Spring 2013 Midterm 2

Topic 7: Algebraic Data Types

Programming II (CS300)

King Saud University Collage of Computer and Information Siences Lab Exam: Monday 15/12/2014

Programming Techniques Laboratory 1 OOP Principles

Transcription:

Model-based Software Engineering (02341, Spring 2017)

Code snippets (week 2)

Ecore model from T01 3

Generated Code // All comments and imports deleted! package dk.dtu.compute.mbse.petrinet; Interface only (separate interface from implementation)! public interface Petrinet extends EObject { String getname(); void setname(string value); Interface with infrastructure for all (generated objects) EList<Node> getnodes(); EList<Arc> getarcs(); } 4

Generated Code // All comments and imports deleted! package dk.dtu.compute.mbse.petrinet; public interface Petrinet extends EObject { String getname(); void setname(string value); EList<Node> getnodes(); Getters and setters for all features with multiplicty up to 1 NB: Only getters for features with multiplicity greater 1 (no setters) EList<Arc> getarcs(); } 5

Implementation Classes Details of Implementation classes not relevant as of now 6

Factory Interface/Class // All comments and imports deleted package dk.dtu.compute.mbse.petrinet; public interface PetrinetFactory extends EFactory { PetrinetFactory einstance = dk.dtu.compute.mbse.petrinet.impl.petrinetfactoryimpl.init(); Petrinet createpetrinet();... and Package Place createplace(); Token createtoken(); PetrinetPackage getpetrinetpackage(); } 7

Package Interface/Class package dk.dtu.compute.mbse.petrinet; public interface PetrinetPackage extends EPackage { String ename = "petrinet"; String ens_uri = "http://mbse.compute.dtu.dk/petrinet"; String ens_prefix = "pn"; and Package PetrinetPackage einstance = dk.dtu.compute.mbse.petrinet.impl.petrinetpackageimpl.init(); int PETRINET = 0; int PETRINET NAME = 0; int PETRINET NODES = 1; int PETRINET ARCS = 2; int PETRINET_FEATURE_COUNT = 3; 8

Package Interface/Class... EClass getpetrinet(); EAttribute getpetrinet_name(); EReference getpetrinet_nodes(); EReference getpetrinet_arcs(); EClass getnode(); and Package... EReference getplace_tokens(); } 9

Enabledness and Firing a Transition t remove add Transition t enabled: for ALL incoming Arcs a: for ONE source Place p of Arc a: find and reserve a token Fire Transition t: for ALL incoming Arcs a: for ONE source Place p of Arc a: find and remove a token for ALL outgoing arcs a: for ONE target Place p of Arc a: add a new Token 10

Loops Code for checking enabledness of a transition static private boolean isenabled(transition transition){ } for (int i = 0; i < transition.getin().size(); i++) { Arc arc = transition.getin().get(i); Place place = (Place) arc.getsource(); if (place.gettokens().isempty()) { return false; } } return true; 11

Loops: Flaws Not defensive: transition could be null arc.getsource()might be not be of type Place Wrong from of for loop (iterating over index) introduces unnecessary artifacts (variable i) invites index problems (in particular i nest loops) Less efficient 12

Loops Better code for checking enabledness of a transition static private boolean isenabled(transition transition){ if (transition!= null) { for (Arc arc : transition.getin()) { Node node = arc.getsource(); if (node instanceof Place) { Place place = (Place) node; if (place.gettokens().isempty()) { return false; } } } } return true; } 13

Problem: Double arcs t Requires two tokens on the place: one for each arc remove add 14

Loops Compute all needed tokens in a mapping first: Map<Place,Integer> needed = new HashMap<Place,Integer>(); for (Arc arc: transition.getin()) { Node node = arc.getsource(); if (node instanceof Place) { Place source = (Place) node; needed.put(source, needed.getordefault(source, 0) + 1); } } Works for Java8 only Count the number of tokens needed for each place 15

Creating new objects?! Token token = new Token(); or Token token = new TokenImpl(); does not work for creating a new token! 16

Use the generated Factory One of the EMF generated classes! Singleton (only instance available) Token token = PetrinetFactory.eINSTANCE.createToken(); Reasons for using factories: Separate implementation from interface Factory is in control of creating appropriate instances 17

In constructor of CompoundCommand... this.append( new RemoveCommand( domain, place, PetrinetPackage.eINSTANCE.getPlace_Tokens(), token);... Token token = PetrinetFactory.eINSTANCE.createToken(); this.append( new CreateChildCommand( domain, place, PetrinetPackage.eINSTANCE.getPlace_Tokens(), token, null)); 18