Saturday, 7 September 2019

Association in java


Association is a relationship between two classes. In this relationship the object of one instance perform an action on behalf of the other class. The typical behavior can be invoking the method of other class and using the member of the other class.
Class A uses Class B.
Example:
  • Employee uses BusService for transportation. 
  • Client-Server model.
  • Computer uses keyboard as input device.

An association is used when one object wants another object to perform a service for it. 
Eg. Computer uses keyboard as input device.
Association UML Notation:
Associations are represented by just the line (no diamond).
          Association  A---->B

Life or existance of the associated objects are independent of each other, They just provide some kind of service to each other.

public class MyMainClass{

public void init(){
new OtherClass.init();
}
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.