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

CSC309 Lecture 03

CSC309 Lecture 03

Software Engineering II
Software Metrics: Structural Quality
(202301)

Javier Gonzalez-Sanchez
PRO

January 16, 2023
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs
    CSC 309
    Software Engineering II
    Lecture 03:
    Software Metrics: Structural Quality
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    www.javiergs.com
    Building 14 -227
    Office Hours: By appointment

    View Slide

  2. jgs
    Previously …

    View Slide

  3. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 3
    code
    Key Ideas CSC 309
    idea
    requirements
    architecture
    design
    quality measure

    View Slide

  4. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 4
    Metrics
    Size
    LOC
    eLOC
    lLOC
    Understandability
    Comments
    Whitespaces
    Complexity
    Average, Max, Min LOC
    Interface Complexity
    Cyclomatic Complexity
    Software Metrics

    View Slide

  5. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 5
    Example Sprint 3

    View Slide

  6. jgs
    Structural Metrics

    View Slide

  7. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 7
    Question 3
    A)
    B)

    View Slide

  8. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 8
    A bad design smells.
    Robert C. Martin describes the following odors (among others):
    1. Rigidity – The system is hard to change because every change forces
    many other changes.
    2. Fragility – Changes cause the system to break in conceptually unrelated
    places.
    3. Immobility – It’s hard to disentangle the system into reusable
    components.
    4. Viscosity – Doing things right is harder than doing things wrong.
    5. Opacity – It is hard to read and understand. It does not express its intent
    well.
    What could be measured or analyzed?

    View Slide

  9. jgs
    Abstractness

    View Slide

  10. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 10
    § 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)
    Abstractness of a Package

    View Slide

  11. jgs
    Instability

    View Slide

  12. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 12
    § 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 between 0 and 1:
    0 only incoming dependencies to
    1 (only outgoing dependencies)
    Instability of a Package

    View Slide

  13. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 13
    • Instability = Cout
    (Cin + Cout)
    Stable Abstraction Principle
    IC
    = ?, A= ?
    IX
    = ?, A= ?
    IA
    = ?, A= ?

    View Slide

  14. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 14
    • Instability = Cout
    (Cin + Cout)
    Stable Abstraction Principle
    IC
    = 1.0, A= ?
    IX
    = 0.5, A= ?
    IA
    = 0.0, A= ?

    View Slide

  15. jgs
    Distance

    View Slide

  16. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 16
    § Distance: how far a package is away from
    the Main Sequence
    § D = A + I – 1
    § Values -1 to 1
    § Absolute Distance |D|
    Distance

    View Slide

  17. jgs
    Principles

    View Slide

  18. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 18
    More stable a package is,
    the more abstract it should be.
    Stable Abstraction Principle

    View Slide

  19. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 19
    § 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.
    Stable Dependency Principle

    View Slide

  20. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 20
    Stable Abstraction Principle
    Abstract
    concrete
    Stable
    Hard to Change
    Only incoming dependencies
    Unstable
    Changeable
    Only outgoing dependencies

    View Slide

  21. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 21
    Question

    View Slide

  22. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 22
    Question
    A)
    B)

    View Slide

  23. jgs
    Test Yourselves

    View Slide

  24. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 24
    Question
    project3.common.model
    project3.client.UI
    project3.server.controller

    View Slide

  25. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 25
    Question

    View Slide

  26. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 26
    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();
    //...
    }
    }
    Question

    View Slide

  27. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 27
    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();
    //...
    }
    }
    Question
    • ISystem
    =
    • IFoo
    =
    • IBar
    • Any candidate for “painful”
    zone:

    View Slide

  28. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 28
    Example A

    View Slide

  29. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 29
    Example B

    View Slide

  30. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 30
    Questions

    View Slide

  31. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 31
    Office Hours
    Tuesday and Thursday 3 - 5 pm
    But an appointment required
    Sent me an email – [email protected]

    View Slide

  32. jgs

    View Slide

  33. jgs
    CSC 309
    Software Engineering II
    Lab 03:
    Structural Metrics
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    www.javiergs.com
    Building 14 -227
    Office Hours: By appointment

    View Slide

  34. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 34
    Your CSC 308 Project
    Box
    Name2
    class Name1 {
    aaa
    bbb
    }
    class Name2 {
    method(){
    Name1
    Cat
    }
    }
    class Cat
    extends Name1 {
    Car
    hello(){
    }
    move(){
    }
    }
    Cat
    Car hello
    move
    Name1
    aaa
    bbb

    View Slide

  35. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 35
    Think about this
    Calculate metrics for your final
    project in CSC 308

    View Slide

  36. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 36
    Let’s Work

    View Slide

  37. jgs
    CSC 309 Software Engineering II
    Javier Gonzalez-Sanchez, Ph.D.
    [email protected]
    Winter 2023
    Copyright. These slides can only be used as study material for the class CSC308 at Cal Poly.
    They cannot be distributed or used for another purpose.

    View Slide