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

CSE564 Lecture 25

CSE564 Lecture 25

Software Design
Model-Driven Development II
(202211)

Javier Gonzalez-Sanchez

September 25, 2020
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

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

    Dr. Javier Gonzalez-Sanchez [email protected] javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. 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
  3. 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();
  4. 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); }
  5. 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 ... }
  6. 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 ...
  7. 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(); } }
  8. 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; } }
  9. 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
  10. 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.
  11. 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 ... }
  12. 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); } }
  13. 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
  14. 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)
  15. jgs 564 00000100 • Instability = Cout (Cin + Cout)

    Stable Abstraction Principle (SAP)
  16. 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|
  17. 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!)
  18. 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.
  19. jgs CSE 564 Computer Systems Fundamentals Javier Gonzalez-Sanchez [email protected] 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.