PPT04_Implementing_Relationships

PPT04_Implementing_Relationships - Implementing...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Implementing Relationships Types of Relationships Association Aggregation Composition Inheritance Implementing Association Create an object reference in one class that references an object of another class. Things to consider What are the reasons for the relationship? Each reason defines one association Why one object needs to know about another object Does each object need to know about the other? Which object is responsible for the relationship? Association Class An association object is one that is created as a result of an association between two other objects. An association object defines the association. RentalCar, Customer, and RentalAgreement. When an association is made between a RentalCar object, and a Customer object, a RentalAgreement object is created. Implementing Aggregation Implemented the same as Association. Additional considerations The aggregate object is responsible for the relationship. Other objects should access component objects through the aggregate object. The aggregate object is responsible for coordination between component objects Implementing Inheritance Generalization/specialization hierarchy General superclass includes attributes and methods that are shared by specialized subclasses Instances of subclass inherit the attributes and methods of the superclass Include additional attributes and methods defined by subclass Keywords: Use extends keyword to implement inheritance public class Pawn extends ChessPiece Use super keyword to invoke superclass constructor super(); To use inheritance: Need to know constructor and method signatures Do not need: Access to source code Knowledge of how class is written Abstract Classes Concrete class Class that can be instantiated Abstract class Class not intended to be instantiated Has at least one abstract method An abstract class must be inherited and the abstract methods must be overriden Page 1 of 4
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Used only to extend into subclasses
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the 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