Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

jgs Previously …

Slide 3

Slide 3 text

jgs 564 00000100 MDD Development Process

Slide 4

Slide 4 text

jgs 564 00000100 Model UML Class Diagram Description

Slide 5

Slide 5 text

jgs 564 00000100 Eclipse Modeling Framework

Slide 6

Slide 6 text

jgs 3. Code

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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();

Slide 9

Slide 9 text

jgs 564 00000100 Interfaces package myModel; public interface Course extends EObject { String getName(); void setName(String value); EList 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); }

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

jgs 564 00000100 Classes :: Course @Override public EList getStudents() { if (students == null) { students = new EObjectContainmentEList (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(); } }

Slide 13

Slide 13 text

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; } }

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

jgs 4. Testing

Slide 16

Slide 16 text

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.

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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); } }

Slide 19

Slide 19 text

jgs 564 00000100 Test Cases

Slide 20

Slide 20 text

jgs Assignment 05 EMF

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

jgs 5. Customize

Slide 23

Slide 23 text

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)

Slide 24

Slide 24 text

jgs 564 00000100 Reference § Eclipse Modeling Framework by Frank Budinsky § EMF project on eclipse.org

Slide 25

Slide 25 text

jgs One last thing Structural Complexity

Slide 26

Slide 26 text

jgs 564 00000100 Example

Slide 27

Slide 27 text

jgs 564 00000100 • Instability = Cout (Cin + Cout) Stable Abstraction Principle (SAP)

Slide 28

Slide 28 text

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|

Slide 29

Slide 29 text

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!)

Slide 30

Slide 30 text

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.

Slide 31

Slide 31 text

jgs 564 00000100 Example MyNewClass OtherClass

Slide 32

Slide 32 text

jgs 564 00000100 Questions

Slide 33

Slide 33 text

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.