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

CSE205 Lecture 05

CSE205 Lecture 05

Object-Oriented Programming and Data Structures
Inheritance I
(202109)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez
PRO

September 15, 2021
Tweet

Transcript

  1. jgs CSE 205 Object-Oriented Programming and Data Structures Lecture 05:

    Inheritance I Dr. Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 2 jgs

    Announcement § Grades posted for Quiz 02 § Review your grade / answers and search for help as needed
  3. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 3 jgs

    Classes
  4. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 4 jgs

    Classes are Better with a Family
  5. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 5 jgs

    Classes are Better with a Family
  6. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 6 jgs

    Classes are Better with a Family
  7. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 7 jgs

    Inheritance § Instead of repeating similar data/method definitions in several classes, we can define one class with the common instance data/methods, and let other classes inherit (extend) these data/method definitions. § Java: parent (super) class and child (sub) class § C++: base class and derived class § New class inherits existing members (variables and functions), add members, and redefine members
  8. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 8 jgs

    Single Inheritance § Java supports single inheritance only, i.e., A child class can have only one parent class (direct parent, not ancestors)
  9. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 9 jgs

    Protected § Child classes do not inherit private variables § Protected variables and methods can be inherited by child classes, but not as accessible as public § If you plan to have a class inherited by other classes, its data should be declared as protected
  10. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 10 jgs

    Protected
  11. jgs Blueprint UML Diagram (

  12. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 12 jgs

    Blueprint
  13. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 13 jgs

    Unified Modeling Language (UML) § document the object-oriented development process § design object-oriented programs
  14. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 14 jgs

    UML Diagrams
  15. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 15 jgs

    UML Class diagram § The Unified Modeling Language Class diagrams show the classes in a system § modifiers § Attributes § methods And the relationships between these classes: § Association / Dependency (calling methods) § Aggregation / Composition (attributes) § Generalization / Specialization / Realization (inheritance)
  16. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 16 jgs

    Class Name Attributes variableName:type = initial value Methods methodName(parameterType):return type UML Class diagram
  17. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 17 jgs

    Diagrams (UML) # name:String + Vehicle() + Car() + - #
  18. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 18 jgs

    Object Oriented Relationships Directed Association Aggregation Generalization Realization
  19. jgs Blueprint UML Diagram )

  20. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 20 jgs

    Classes are Better with a Family
  21. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 21 jgs

    Classes are Better with a Family (UML)
  22. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 22 jgs

    Note In the Class Diagram: § Parameters are optional § Inherited members are implicit, just like with the source code
  23. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 23 jgs

    Questions
  24. jgs To be continued…

  25. jgs CSE 205 Object-Oriented Programming and Data Structures Javier Gonzalez-Sanchez,

    Ph.D. javiergs@asu.edu Fall 2021 Copyright. These slides can only be used as study material for the class CSE205 at Arizona State University. They cannot be distributed or used for another purpose.