$30 off During Our Annual Pro Sale. View Details »

CSE564 Lecture 25

CSE564 Lecture 25

Software Design
Model-Driven Development II
(202211)

Javier Gonzalez-Sanchez
PRO

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

    View Slide

  2. jgs
    Previously …

    View Slide

  3. jgs
    564 00000100
    MDD Development Process

    View Slide

  4. jgs
    564 00000100
    Model
    UML Class Diagram
    Description

    View Slide

  5. jgs
    564 00000100
    Eclipse Modeling Framework

    View Slide

  6. jgs
    3. Code

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  12. 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();
    }
    }

    View Slide

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

    View Slide

  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

    View Slide

  15. jgs
    4. Testing

    View Slide

  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.

    View Slide

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

    View Slide

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

    View Slide

  19. jgs
    564 00000100
    Test Cases

    View Slide

  20. jgs
    Assignment 05 EMF

    View Slide

  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

    View Slide

  22. jgs
    5. Customize

    View Slide

  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)

    View Slide

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

    View Slide

  25. jgs
    One last thing
    Structural Complexity

    View Slide

  26. jgs
    564 00000100
    Example

    View Slide

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

    View Slide

  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|

    View Slide

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

    View Slide

  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.

    View Slide

  31. jgs
    564 00000100
    Example
    MyNewClass
    OtherClass

    View Slide

  32. jgs
    564 00000100
    Questions

    View Slide

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

    View Slide