cs31 lecture 13

Oo languages may have different default

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ful: other OO languages may have different default implementations! Strong advise: do not do multiple inheritance unless you know what you are doing You probably want to use interfaces and not class inheritance 5 Some guidelines to determine a good hierarchy RULE 1) If A : B in the hierarchy, then the sentence “A is a B” should make full sense Example: “a rectangle is a square” vs. “a rectangle is an object” Meaningful design may not lead to maximal code reuse RULE 2) If A : B in the hierarchy, then A must “extend” the behavior/functionalities/properties of B 6 Quick summary How a method/attribute can be accessed outside the current class is determined by public/protected/private Protected attributes/methods can only be accessed from within the class and subclasses of it Private attributes/methods can only be accessed from the class itself Public attributes/methods can be accessed from anywhere How multiple inheritance is handled depends 7 Design question: inheritance vs. attribute? When designing a project, a question often occurs Do I make B inherit from A? Or, do I add an object of type A as attribute of B? This can be solved for instance with the “is a” test Both choices can lead to a valid implementation But design may be less clear in one case vs. the other 8 Examples Let’s design a hierarchy for images 9...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern