Javatpoint Logo

what is delegates in java

By: anjani*** On: Mon Aug 05 11:23:14 EDT 2013     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
Tell me about delegates with explanationUp0Down

 
delegate is a design pattern and its following two type of design pattern
1- proxy design pattern
2-Business delegate design pattern
example of business delegates

package com.businessdelegates;

import com.dto.AccountDTO;
import com.locator.ServiceLocator;
import com.service.AccountServiceInt;

public class AccountDelegate {
private static AccountServiceInt accountServiceInt = null;

public static String openAccount(AccountDTO accountDTO) throws Exception {
accountServiceInt = ServiceLocator
.getInstance().getaccountServiceInt();

return accountServiceInt.openAccount(accountDTO);
}

public static String lockAccount(AccountDTO accountDTO) throws Exception {
accountServiceInt = ServiceLocator
.getInstance().getaccountServiceInt();

return accountServiceInt.lockAccount(accountDTO);
}

public static double balance(Long id) throws Exception {
accountServiceInt = ServiceLocator
.getInstance().getaccountServiceInt();

return accountServiceInt.balance(id);
}

public static AccountDTO get(Long id) throws Exception {
accountServiceInt = ServiceLocator
.getInstance().getaccountServiceInt();

return accountServiceInt.get(id);
}

public static String fundTransfer(Long accid1, Long accid2,
Double amount) throws Exception {
accountServiceInt = ServiceLocator
.getInstance().getaccountServiceInt();

return accountServiceInt.fundTransfer(accid1, accid2, amount);
}

public static String withdrawal(Long id, Double amount) throws Exception {
accountServiceInt = ServiceLocator
.getInstance().getaccountServiceInt();

return accountServiceInt.withdrawal(id, amount);
}
public static String deposite(Long id, Double amount) throws Exception {
accountServiceInt = ServiceLocator
.getInstance().getaccountServiceInt();

return accountServiceInt.deposite(id, amount);
}

}
Image Created0Down

By: [email protected] On: Mon Aug 05 13:24:36 EDT 2013 Question Reputation0 Answer Reputation7 Belt Series Points0 7User Image
Are You Satisfied :6Yes5No
 
you wrap a particular type of object and pass (delegate) method calls to the wrapped object, this is the fundamental for the Decorator pattern. And that's achieved through a HAS-A relationship.

you can use delegation when you want to use another class's functionality,as is, without changing that behavior at all.
In another words,if you need to use functionality in another class,but you don't want to change that functionality,consider using delegation instead of inheritance.
Image Created0Down

By: [email protected] On: Tue Aug 06 04:14:17 EDT 2013 Question Reputation0 Answer Reputation392 Belt Series Points0 392User Image
Are You Satisfied :2Yes2No
 
When an object receives a request, the object can either handle the request itself or pass the request on to a second object to do the work. If the object decides to pass the request on, you say that the object has forwarded responsibility for handling the request to the second object. Image Created0Down

By: [email protected] On: Wed Aug 07 02:31:45 EDT 2013 Question Reputation0 Answer Reputation153 Belt Series Points0 153User Image
Are You Satisfied :2Yes2No