Introduction
- While developing applications we do not code from scratch,Instead we enhance the already available code
- For this we use a relationship Advantages Of Using Relationship a. Optimisation Of Code b. Code Reusability c. Execution Time
Types Of Relationship
- IS-A
- HAS-A IS-A relationship basically implies inheritance using extends keyword
HAS-A
- It defines an association between two entities/classes
- This helps in communication and data transfer between two entities/classes.
- 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
- 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
Dependency Injection: The process of inserting the dependent object into target object is called dependency injection
Target Object: The object which is given to the developer to the user is called as the target object
- 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
- This can be done through constructor
- Through settter