HAS-A Relationship

HAS-A Relationship

Introduction

  1. While developing applications we do not code from scratch,Instead we enhance the already available code
  2. For this we use a relationship Advantages Of Using Relationship a. Optimisation Of Code b. Code Reusability c. Execution Time

Types Of Relationship

  1. IS-A
  2. HAS-A IS-A relationship basically implies inheritance using extends keyword

HAS-A

  1. It defines an association between two entities/classes
  2. This helps in communication and data transfer between two entities/classes.
  3. In Java we have 4 types of association

a. one to one b. one to many c. many to many d. many to one

How to achieve association

  1. To achieve association between two entities we have to display either a single reference or an array of reference in other class entities

Key Terms In HAS A relationship

  1. Dependency Injection: The process of inserting the dependent object into target object is called dependency injection

  2. Target Object: The object which is given to the developer to the user is called as the target object

  3. Dependent Object: The object that helps the target object is called a a dependent object

Note 1. The object which helps is the dependent object

       2. The object who needs help is the target object

example: student object needs the address object student object is the target object address object is the dependent object

How to perform dependency injection

  1. This can be done through constructor
  2. Through settter