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

CSE360 Tutorial 05

CSE360 Tutorial 05

Introduction to Software Engineering
The SOLID Principles II
(202206)

Javier Gonzalez-Sanchez
PRO

June 14, 2022
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. CSE360
    Introduction to Software Engineering
    Lecture:
    The SOLID Principles II
    Javier Gonzalez-Sanchez
    [email protected]
    javiergs.engineering.asu.edu
    Office Hours: By appointment

    View Slide

  2. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 2
    Announcement
    • Monday, June 20

    View Slide

  3. Previously …

    View Slide

  4. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 4
    Design Principles
    There are five key design principles to consider in
    Object-Oriented:
    • Single Responsibility Principle (SRP)
    • Open-Closed Principle (OCP)
    • Liskov Substitution Principle (LSP)
    • Interface Segregation Principle (ISP)
    • Dependency Inversion Principle (DIP)

    View Slide

  5. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 5
    Single Responsibility Example

    View Slide

  6. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 6
    Open-Close Example

    View Slide

  7. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 7
    Liskov Substitution
    • Imagine you already have a class Circle, and you are asked
    to create a class Cylinder.
    • Or maybe you have a class Rectangle, and you are asked to
    create a class Square (a square is a rectangle with the same
    width and height).
    • Or you have a class LinkedList, and you are asked to create a
    class PersistentLinkedList (one that writes out its elements to a
    stream and can read them back later).
    If you are tempted to use inheritance from Circle to Cylinder, or
    from Rectangle to Square, or
    from LinkedList to PersistentLinkedList, i.e., create a parent-child
    relationship for any of these cases, you will have problems.

    View Slide

  8. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 8
    Interface Segregation
    • Clients should not be forced to depend on methods
    that they do not use.
    • ISP deals with the disadvantage of “fat” interfaces
    (or abstract classes).
    • ISP recommends to broke up interfaces with a lot of
    methods into several interfaces.

    View Slide

  9. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 9
    Dependency Inversion Example

    View Slide

  10. Connecting the Dots
    SOLID Principles

    View Slide

  11. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 11
    Project – User create dots

    View Slide

  12. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 12
    Project – User selects Cluster and clicks Run

    View Slide

  13. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 13
    Project – User selects Cluster and clicks Run

    View Slide

  14. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 14
    Project – User selects Line and clicks Run

    View Slide

  15. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 15
    Project – User selects Line and clicks Run

    View Slide

  16. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 16
    Connecting the Dots

    View Slide

  17. CSE360 – Introduction to Software Engineering
    Javier Gonzalez-Sanchez
    [email protected]
    Summer 2022
    Disclaimer. These slides can only be used as study material for the class CSE360 at ASU. They cannot be distributed or used for another purpose.

    View Slide