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
PRO

September 24, 2020
Tweet

More Decks by Javier Gonzalez

Other Decks in Programming

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. jgs Previously …

  3. jgs 564 00000100 MDD Development Process

  4. jgs 564 00000100 Model UML Class Diagram Description

  5. jgs 564 00000100 Eclipse Modeling Framework

  6. jgs 3. Code

  7. 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
  8. 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();
  9. 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); }
  10. 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 ... }
  11. 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 ...
  12. 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(); } }
  13. 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; } }
  14. 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
  15. jgs 4. Testing

  16. jgs 564 00000100 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.
  17. jgs 564 00000100 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 ... }
  18. jgs 564 00000100 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); } }
  19. jgs 564 00000100 Test Cases

  20. jgs Assignment 05 EMF

  21. jgs 564 00000100 Assignment UML Class Diagram 1. Define the

    Model in EMF (take a screen shoot) 2. Use the Code to Create a Class Diagram (only the Model and Test packages and include both interfaces and implementations). It will be bigger and more complex that the one provided 3. Create a document with the screen shoot of your model and your UML diagram. The diagram is going to be bigger and different from the one used as input! Car Engine Wheel
  22. jgs 5. Customize

  23. jgs 564 00000100 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)
  24. jgs 564 00000100 Reference § Eclipse Modeling Framework by Frank

    Budinsky § EMF project on eclipse.org
  25. jgs One last thing Structural Complexity

  26. jgs 564 00000100 Example

  27. jgs 564 00000100 • Instability = Cout (Cin + Cout)

    Stable Abstraction Principle (SAP)
  28. jgs 564 00000100 Distance § Distance: how far a package

    is away from the Main Sequence § D = A + I – 1 § Values -1 to 1 § Absolute Distance |D|
  29. jgs 564 00000100 Example ITeamA = 6 / 0 +

    6 = 1 ATeamA = 0 DTeamA = 0 + 1 – 1 = 0 IJlabel = 0 / 4 + 0 = 0 AJlabel = 0 DJlabel = 0 + 0 – 1 = -1 |Djlabel | = 1 Pain Zone (just an example!)
  30. jgs 564 00000100 Stable Dependency Principle (SDP) § Every dependency

    between modules should terminate on a module whose Instability is less than or equal to the depending module's Instability. § Every dependency between modules should terminate on a module whose Abstractness is greater than or equal to the depending module's Abstractness.
  31. jgs 564 00000100 Example MyNewClass OtherClass

  32. jgs 564 00000100 Questions

  33. 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.