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

CSE564 Lecture 26

CSE564 Lecture 26

Software Design
Model-Driven Development II
(202104)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez
PRO

September 26, 2020
Tweet

Transcript

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

    Dr. Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. jgs 564 00000100 Announcements § Assignment 06 opens today, and

    it is due on April 26. It is an assignment about EMF (described at the end of this lecture) It can be done in a couple of hours (very simple) We give you a week so you can organize as needed No extensions If you have an exam on April 26, complete the assignment before (today, tomorrow, etc.)
  3. jgs 564 00000100 Schedule § Final Exam is scheduled Wednesday

    April 21 during the lecture time
  4. jgs 564 00000100 Final Exam § Final Exam is comprehensive

    § Look to the review done in lecture 16 § 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. jgs 564 00000100 Grades § 6 Quizzes (25%), therefore 4.16%

    each § 6 Assignments (25%), therefore 4.16% each. § Midterm Exam (25%). Grades are posted. You could need Lockdown Browser to access. § Final Exam (25%).
  6. jgs Previously …

  7. jgs 564 00000100 MDD Development Process

  8. jgs 564 00000100 Model UML Class Diagram Description

  9. jgs 2. Code Generation

  10. jgs 564 00000100 Eclipse Modeling Framework

  11. jgs 564 00000100 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. jgs 564 00000100 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. jgs 564 00000100 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. jgs 564 00000100 Step 3 :: Generate Code

  15. jgs 564 00000100 Step 3 :: Generate Code Could you

    create a class diagram for the package myModel?
  16. jgs 3. Code

  17. jgs 564 00000100 § 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. jgs 564 00000100 § 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. jgs 564 00000100 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. jgs 564 00000100 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. jgs 564 00000100 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. jgs 564 00000100 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. jgs 564 00000100 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. jgs 564 00000100 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 Assignment 06

  26. jgs 564 00000100 Assignment 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
  27. jgs 564 00000100 Reference § Eclipse Modeling Framework by Frank

    Budinsky § EMF project on eclipse.org
  28. 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.