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

SER516 Lecture 19a

SER516 Lecture 19a

Software Agility: Project and Process Management
Structural Metrics I and II
(202003)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez

February 23, 2019
Tweet

Transcript

  1. SER516 Software Agility: Project and Process Management Lecture 19. Structural

    Metrics I, II and III Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu Office Hours: By appointment
  2. Kent Beck’s Rules for Simple Design

  3. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 3 Checklist

    ü Readability (names, sizes, modularity, etc.) ü Dependency injection (use parameters), ü separation of concerns (patterns), ü Low Coupling (use, has, is, et al)
  4. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 4 1.

    Write tests § Writing test cases drive to Single Responsibility (SRP), dependency injection (DI), and interfaces. § Writing test cases minimize coupling because tight coupling makes it difficult to write tests. § Refactoring: increase cohesion, decrease coupling, separate concerns, modularize, shrink functions and classes, choose better names, and so on. § Having tests eliminates the fear that cleaning up the code will break it.
  5. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 5 2.

    Eliminate duplication § Duplication (LOC or methods) represents additional work, risk, and unnecessary complexity. § Use Inheritance à overloading § Common mistake: get our code working and then move on to the next problem. Take care of what you have created!
  6. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 6 3.

    Ensure Expressiveness § The majority of the cost is in long-term maintenance. § It is critical to understand what the system does. § Select good names, keep items small, use patterns (observer, visitor, command, interpreter, mediator, decorator, adapter, singleton, factory, etc.). § Tests should also be expressive. § Common mistake: get our code working and then move on to the next problem. § Take care of what you have created!
  7. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 7 4.

    Minimize the number of items § Do not end with a program that have too many tiny classes and methods. Keep classes and methods counts low. § Dogmatism vs Pragmatism. § This rule is lowest priority compared with the other principles and rules. But, it is a rule. Do not ignore it.
  8. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 8 Test

    Yourselves Does your project follow these rules?
  9. Structural Quality 18

  10. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 10 Question

    1 A) B)
  11. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 11 Question

    2 Problem? Solution?
  12. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 12 Question

    3 A) B)
  13. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 13 What

    could be measured or analyzed? Rigidity, Fragility, Immobility, Viscosity, Opacity
  14. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 15 Goal

    § Measuring Quality § Dependency Analysis § Detect “potential” design flaws
  15. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 16 Principles

    1. Acyclic Dependency Principle (ADP) 2. Stable Dependency Principle (SDP) 3. Stable Abstraction Principle (SAP)
  16. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 17 Step

    1. Dependency Graph
  17. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 18 Step

    1. Dependency Graph What are these numbers?
  18. Acyclic Dependency Principle

  19. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 20 Problem

    Definition § Cycled components can only be used together: they can only be tested, reused, deployed and understood together. § Every node on a cycle depends on any other.
  20. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 21 Acyclic

    Dependencies Principle § Avoid dependency cycles § Tangle. A subgraph with at least two nodes, where each node is reachable from each other. § Tangled metric. values greater zero indicate cyclic dependencies.
  21. Stable Abstraction Principle

  22. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 23 Stable

    Abstraction Principle More stable a package is, the more abstract it should be.
  23. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 24 Abstractness

    of a Package § Express the portion of contained abstract types. § It is a value 0 to 1: 0 (only concrete classes) to 1 (only interfaces and abstract classes)
  24. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 25 Instability

    of a Package § Indicates whether the package is mainly used by other artifacts (stable – hard to change) or if it mainly depends on other artifacts (instable – changeable). § It is a value 0 to 1: 0 only incoming dependencies to 1 (only outgoing dependencies)
  25. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 26 Instability

    of a Package § Indicates whether the package is mainly used by other artifacts (stable – hard to change) or if it mainly depends on other artifacts (instable – changeable). § It is a value 0 to 1: 0 only incoming dependencies to 1 (only outgoing dependencies)
  26. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 27 •

    Instability = Cout (Cin + Cout) Stable Abstraction Principle IC = ?, A= ? IX = ?, A= ? IA = ?, A= ?
  27. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 28 •

    Instability = Cout (Cin + Cout) Stable Abstraction Principle IC = 1.0, A= ? IX = 0.5, A= ? IA = 0.0, A= ?
  28. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 29 Stable

    Abstraction Principle Abstract concrete Stable Hard to Change Only incoming dependencies Unstable Changeable Only outgoing dependencies
  29. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 30 Question

  30. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 31 Question

    A) B)
  31. Stable Dependency Principle

  32. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 33 Stable

    Dependency Principle § Every dependency between modules should terminate on a module whose Instability metric is less than or equal to the depending module's Instability metric. § Every dependency between modules should terminate on a module whose Abstractness metric is greater than or equal to the depending module's Abstractness metric.
  33. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 34 Question

    3 (again) A) B)
  34. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 35 SAP

    + SDP § Distance: how far a package is away from the Main Sequence § D = A + I – 1 § Values -1 to 1 § Absolute Distance |D|
  35. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 36 Question

    project3.common.model project3.client.UI project3.server.controller
  36. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 37 Question

  37. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 38 Question

    public class Foo { Bar b= new Bar(new Car()); public Foo (Car c) { c.doIt(b); } public void m (Delta d) { d.action(b); } } public class System { public ... main ( ...) { Foo f = new Foo(); //... } }
  38. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 39 Question

    public class Foo { Bar b= new Bar(new Car()); public Foo (Car c) { c.doIt(b); } public void m (Delta d) { d.action(b); } } public class System { public ... main ( ...) { Foo f = new Foo(); //... } } • Tangled: • ISystem = • IFoo = • IBar • Afoo • Any candidate for “painful” zone:
  39. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 40 Question

    A:0 Ca:1 Ce:4 I:4/5=0.8 D:-0.2 A:0 Ca:2 Ce:3 I:3/5=0.6 D:-0.4 A:0 Ca:1 Ce:3 I:3/4=0.75 D:-0.25
  40. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 41 Example

  41. Tool

  42. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 48 Tools

    1. Download and install STAN https://stan4j.com Stand alone or Eclipse plug-in 2. Review your “Robert C. Martin” metrics: Ca, Ce, I, A, D. 3. Review “Violations” report 4. Review “Distance” plot 5. Review Dependency / Composition Graph
  43. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 49 Example

    of Violations Report
  44. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 50 PS

    about LOC per method § around 20 is perfect, § up to 50 is still fine, § up to 100 is critical, § above 150 is really bad, and § more than 250 is
  45. Javier Gonzalez-Sanchez | SER516 | Spring 2018 | 51 Reference

    § Agile Software Development: Principles, Patterns, and Practices. Robert C. Martin. Prentice Hall. 2006. Chapter 30.
  46. SER516 – Software Agility Javier Gonzalez-Sanchez javiergs@asu.edu Spring 2018 Disclaimer.

    These slides can only be used as study material for the SER516 course at ASU. They cannot be distributed or used for another purpose.