CSE460 Lecture 13

CSE460 Lecture 13

Software Analysis and Design
Object-Oriented Principles II
(202009)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez

July 13, 2020
Tweet

Transcript

  1. jgs CSE 460 Software Analysis and Design Lecture 13: Object-Oriented

    Principles II Dr. Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 2 jgs

    Announcement § Assignment 02 is due Wednesday (September 23) o Analysis - Use case diagram o Design - Class Diagram o Implementation - Source Code
  3. jgs Previously

  4. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 4 jgs

    Do This Encapsulation Abstraction Hierarchical Relationships Polymorphism Concurrency Persistency
  5. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 5 jgs

    Avoid This
  6. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 6 jgs

    Avoid This Create code Elegant and Efficient –Bjarne Stroustrup Create code Simple and Direct –Grady Booch Create code looks like written by someone who cares –Michael Feathers
  7. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 7 jgs

    Clean Code Principles § Readability Use Meaningful Names for Classes, Methods, and Variables Follow coding guidelines: e.g. read the Java Style Reference § KISS (Keep It Simple by K. Johnson) for your reader Small functions that do one thing § DRY (Do not Repeat Yourself): Avoid Code Bloat § Decoupling
  8. jgs Readability, KISS, DRY Examples

  9. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 9 jgs

    Readability Naming Review Language Guidelines
  10. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 10 jgs

    Readability Is the comment needed? Public vs Private? What about customize the Exception?
  11. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 11 jgs

    Readability
  12. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 12 jgs

    Readability … … … 500 LOC in a method… it is to much!
  13. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 13 jgs

    How many LOC per method? § around 20 is perfect, § up to 50 is still fine, § up to 100 is critical, § above 150 is bad, and § more than 250 is
  14. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 14 jgs

    KISS Create code Simple and Direct Could we make this code short? Is the Runnable needed? Is the Exception needed?
  15. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 15 jgs

    DRY 1 or 2?
  16. jgs Decoupling

  17. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 17 jgs

    What to do? Rigidity, Fragility, Immobility, Viscosity, Opacity
  18. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 18 jgs

    1. Dependency Injection public class ClientFrame { ... public ClientFrame() { ... = new PlotPanel(); ... = new FacePanel(); ... = new ConsolePanel(); ... = new JButton(); ... = new JLabel(); } } public class ClientFrame { public ClientFrame(Jpanel a, Jpanel b) { } }
  19. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 19 jgs

    Instability § Indicates whether the package is mainly used by other artifacts (stable – hard to change) or if it mainly depends on other artifacts (instable – changeable). § Instability = Cout (Cin + Cout) § It is a value 0 to 1: 0 only incoming dependencies to 1 (only outgoing dependencies)
  20. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 20 jgs

    • Instability = Cout (Cin + Cout) 2. Stable Abstraction Principle
  21. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 21 jgs

    3. Stable Dependency Principles § 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.
  22. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 22 jgs

    Reference Clean Code (2008) Robert C. Martin. Prentice Hall
  23. jgs CSE 460 Software Analysis and Design Javier Gonzalez-Sanchez javiergs@asu.edu

    Fall 2020 Disclaimer. These slides can only be used as study material for the class CSE460 at ASU. They cannot be distributed or used for another purpose.