iFocus.Life News News - Breaking News & Top Stories - Latest World, US & Local News,Get the latest news, exclusives, sport, celebrities, showbiz, politics, business and lifestyle from The iFocus.Life,

Dependence

106 11
Definition:

Dependence is a relationship between two classes where one class uses another. It's described as the "uses-a" relationship. Typically the relationship between the two classes is short-term. In Java, the dependence relationship can be best seen when an object is passed as a parameter in a method call. Once the method has finished executing, the object is no longer needed and is discarded.


Examples:


Imagine a Telephone class that allows users to make phone calls. It is a pre-pay system that only allows a user to start a phone call if they have at least five dollars in their account. The user's account details are kept in an Account class:

public class Account {  private BigDecimal balance;  public BigDecimal getBalance()   {     return balance;   }   //rest of account class }public class Telephone {  public void startCall(Account customerAccount)   {     if (customerAccount.getBalance().compareTo(new BigDecimal(5.00)) >= 0)     {       //start call     }   }  //rest of Telephone class }
The Telephone class is using an Account object but once the method has finished executing it will be discarded.

Glossary:

#ABCDEFGHIJKLMNOPQRSTUVWXYZ
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time
You might also like on "Technology"

Leave A Reply

Your email address will not be published.