Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSE564 Lecture 24

CSE564 Lecture 24

Software Design
Model-Driven Development II
(202011)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez

September 24, 2020
Tweet

Transcript

  1. jgs CSE 564 Software Design Lecture 24: Model-Driven Development II

    Dr. Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 2 jgs

    Announcements § Quiz 04 opens today, and it is due on December 1. It is an assignment about EMF (described at the end of this lecture) § Quiz 05 opens today, and it is due on December 1. Questions about Software Design
  3. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 3 jgs

    Grades § 5 Quizzes (25%), therefore 5% each § 6 Assignments (25%), therefore 4.16% each. Notice that Assignment 4.1 was replaced by 4.2 § Midterm Exam (25%). Grades are posted. You need Lockdown Browser to access. § Final Exam (25%).
  4. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 4 jgs

    Final Exam § Final Exam is comprehensive § Take a look to the review done in lecture 15 § Additionally, a) Software design, i.e., class diagrams, coding, match code and design b) Design Smells, i.e., is this a correct design (y/n) ? c) Software Architecture and Architecture Patterns d) Model-Driven Development and EMF
  5. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 5 jgs

    Schedule § Final Exam is scheduled December 1 during the lecture time … Me and many other students who take SER 531 and SER 540 along with CSE 564 have all 3 of our exams on 1st of December I will send a survey. But since we announce it (October 13) to be December 1, it could probably stay that way, unless unanimously request to change. I will let you know as soon as everyone answer the survey
  6. jgs Previously …

  7. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 7 jgs

    MDD Development Process
  8. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 8 jgs

    Model UML Class Diagram Description
  9. jgs 2. Code Generation

  10. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 10 jgs

    Eclipse Modeling Framework
  11. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 11 jgs

    Generator Model § Create a generator model. This allows to configure properties for the code generation that are not part of the model itself. § Generate a maximum of four different plugins for a defined model: 1. Model plugin contains all entities, packages and factories to create instances of the model. 2. Edit plugin contains providers to display a model in a UI. For example, the providers offer a label for every model element, which can be used to display an entity showing an icon and a name. 3. Editor plugin is a generated example editor to create and modify instances of a model. 4. Test plugin contains templates to write tests cases for a model.
  12. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 12 jgs

    Step 3 :: Generate Code § Right click the model folder in the project then § New → Other… → EMF Generator Model → Next § and enter myModel.genmodel as the file name. § Select Ecore model as the model importer. § select Browse Workspace… and select our previously created myModel.ecore
  13. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 13 jgs

    Step 3 :: Generate Code § Based on the generator model, we can now generate the source code. § EMF allows you to generate 4 different plugins. § To generate the plugins, right-click on the root node of the genmodel and select the plugin. For our tutorial, please select “generate all”.
  14. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 14 jgs

    Step 3 :: Generate Code
  15. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 15 jgs

    Step 3 :: Generate Code Could you create a class diagram for the package myModel?
  16. jgs 3. Code

  17. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 17 jgs

    § For each class in your model, there is a corresponding generated § Java interface § Java implementation class § For each package, there is a § XXXPackage interface and implementation class § XXXFactory interface and implementation class
  18. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 18 jgs

    § These are singletons, to access the instances use § XXXPackage.eINSTANCE § XXXFactory.eINSTANCE § Use the Factory to create instances of your model classes, e.g: TaskList t = ExampleFactory.eINSTANCE.createTaskList(); § Use the Package to access the meta-model definition, e.g: EClass c = ExamplePackage.eINSTANCE.getTaskList(); List attrs = c.getEAttributes();
  19. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 19 jgs

    Interfaces package myModel; public interface Course extends EObject { String getName(); void setName(String value); EList<Student> getStudents(); } public interface Student extends EObject { String getName(); void setName(String value); int getGpa(); void setGpa(int value); boolean isHasScholarship(); void setHasScholarship(boolean value); Computer getComputer(); void setComputer(Computer value); } public interface Computer extends EObject { String getBrand(); void setBrand(String value); }
  20. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 20 jgs

    Interfaces package myModel; public interface MyModelFactory extends EFactory { MyModelFactory eINSTANCE = myModel.impl.MyModelFactoryImpl.init(); Course createCourse(); Student createStudent(); Computer createComputer(); MyModelPackage getMyModelPackage(); } public interface MyModelPackage extends EPackage { String eNAME = "myModel"; String eNS_URI = "https://org/eclipse/example/myModel"; String eNS_PREFIX = "org.eclipse.example.myModel"; MyModelPackage eINSTANCE = myModel.impl.MyModelPackageImpl.init(); // more ... }
  21. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 21 jgs

    Classes :: Course package myModel.impl; public class CourseImpl extends MinimalEObjectImpl.Container implements Course { protected static final String NAME_EDEFAULT = null; protected String name = NAME_EDEFAULT; protected EList<Student> students; protected CourseImpl() { super(); } @Override protected EClass eStaticClass() { return MyModelPackage.Literals.COURSE; } @Override public String getName() { return name; } @Override public void setName(String newName) { String oldName = name; name = newName; if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, MyModelPackage.COURSE__NAME, oldName, name)); } // continue ...
  22. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 22 jgs

    Classes :: Course @Override public EList<Student> getStudents() { if (students == null) { students = new EObjectContainmentEList<Student> (Student.class, this, MyModelPackage.COURSE__STUDENTS); } return students; } // more ... @Override public String toString() { if (eIsProxy()) return super.toString(); StringBuilder result = new StringBuilder(super.toString()); result.append(" (name: "); result.append(name); result.append(')’); return result.toString(); } }
  23. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 23 jgs

    Classes :: Student package myModel.impl; public class StudentImpl extends MinimalEObjectImpl.Container implements Student { protected boolean hasScholarship = HAS_SCHOLARSHIP_EDEFAULT; protected Computer computer; @Override public void setComputer(Computer newComputer) { Computer oldComputer = computer; computer = newComputer; if (eNotificationRequired()) eNotify(new ENotificationImpl (this, Notification.SET, MyModelPackage.STUDENT__COMPUTER, oldComputer, computer)); } @Override public Computer getComputer() { if (computer != null && computer.eIsProxy()) { InternalEObject oldComputer = (InternalEObject)computer; computer = (Computer)eResolveProxy(oldComputer); if (computer != oldComputer) { if (eNotificationRequired()) eNotify(new ENotificationImpl (this, Notification.RESOLVE, MyModelPackage.STUDENT__COMPUTER, oldComputer, computer)); } } return computer; } }
  24. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 24 jgs

    Why is This Better than Writing POJOs? § plain old Java object (POJO) § We have generated over 1,000 LOC, § Even very simple code is considered to be worth $1 per LOC. So, $1,000 just by clicking some buttons
  25. jgs 4. Testing

  26. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 26 jgs

    Test Cases § Generated test class for all the entities of your model. § Add methods starting with “test” to create single test cases. § Run test cases with a right-click on the test class then. “Debug As” => “JUnit Test”. In this context, test cases are very simple way of exploring and using the API of the generated classes.
  27. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 27 jgs

    Test Cases package myModel.tests; import junit.framework.TestCase; import junit.textui.TestRunner; import myModel.Course; import myModel.MyModelFactory; import myModel.Student; public class CourseTest extends TestCase { public static void main(String[] args) { TestRunner.run(CourseTest.class); } public CourseTest(String name) { super(name); } // more ... }
  28. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 28 jgs

    Test Cases § Use the MyModelFactory to create a Course and a Student public class CourseTest extends TestCase { // original code... public void testCourseStudentReference() { Course course = MyModelFactory.eINSTANCE.createCourse(); Student s1 = MyModelFactory.eINSTANCE.createStudent(); course.getStudents().add(s1); assertEquals(course.getStudents().get(0), s1); } }
  29. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 29 jgs

    Test Cases
  30. jgs Quiz 04

  31. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 31 jgs

    Quiz 04 UML Class Diagram 1. Define the Model in EMF (take a screen shoot) 2. Generate Code (take a screen shoot) 3. Use the Code to Create a Class Diagram (only the Model package but include both interfaces and implementations). It will be bigger and more complex that the one provided 1. Create a test case to create (using the factory) one instance of each class EMF (take a screen shoot) 2. Run it (take a screen shoot)
  32. jgs 5. Customize

  33. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 33 jgs

    Frameworks For storing and versioning EMF model instances: § EMFStore (Model Repository) § CDO (Model Repository) § Teneo (Database Back-end) For Views: § EMF UI § EMF Listener § EMF Forms. § Graphiti (Graphical Editor) § Graphical Modeling Framework (Graphical Editor) § Extended Editing Framework (Advanced Property View)
  34. Javier Gonzalez-Sanchez | CSE564 | Fall 2020 | 34 jgs

    Reference § Eclipse Modeling Framework by Frank Budinsky § EMF project on eclipse.org
  35. jgs CSE 564 Computer Systems Fundamentals Javier Gonzalez-Sanchez javiergs@asu.edu Fall

    2020 Disclaimer. These slides can only be used as study material for the class CSE564 at ASU. They cannot be distributed or used for another purpose.