Note that there are some explanatory texts on larger screens.

plurals
  1. POShould I use Observer pattern to notify Customer object when the customer's Account has made deposit transaction?
    text
    copied!<p>I do have Customer and Account business objects which implement <code>ICustomer</code> and <code>IAccount</code> respectively. I also have service layers for each business objects. <code>AccountService</code> (<code>addAccount</code> , <code>deposit()</code>, <code>withdraw()</code> methods) and CustomerService (<code>addCustomer</code>, <code>addAdressForACustomer</code>, <code>removeCustomer()</code> etc.. methods).</p> <p>I want my system to user Observer patter so that I send email notification to customers when one of the transactions (<code>withdraw()</code> or <code>deposit()</code> methods succeed). I understand that the customer is the observer and the account is the subject which should notify the customer. But customer can have different accounts and should be notified for each of them when a transaction occurs.</p> <p>Should I add <code>notifyCustomer()</code> methods to my Account business object or in the service by extending Observable Java class? I am confused a bit how to implement that. Should Observer pattern a good thing to use it in this case?</p> <p>Thanks</p> <p>Here is a sample code of my business objects</p> <pre><code>package business; import java.math.BigDecimal; public class Account implements IAccount { private int accountNumber; private IParty owner; public Account(int accountNumber, IParty owner, BigDecimal balance) { super(); this.accountNumber = accountNumber; this.owner = owner; this.balance = balance; } private BigDecimal balance; public int getAccountNumber() { return accountNumber; } public void setAccountNumber(int accountNumber) { this.accountNumber = accountNumber; } public IParty getOwner() { return owner; } public void setOwner(IParty owner) { this.owner = owner; } public BigDecimal getBalance() { return balance; } public void setBalance(BigDecimal balance) { this.balance = balance; } } package business; import java.util.Date; public class Person extends Party implements IPerson { private Date birthDate; public Person(String name, IAddress address,Date birthDate) { super(name, address); this.birthDate=birthDate; // TODO Auto-generated constructor stub } public Date getBirthDate() { return birthDate; } public void setBirthDate(Date birthDate) { this.birthDate = birthDate; } } package service; import java.math.BigDecimal; import java.util.List; import business.Account; import business.IAccount; import business.IAccountEntry; import business.IParty; public class AccountService implements IAccountService { /* (non-Javadoc) * @see service.IAccountService#createAccount() */ IDaoService daoService; @Override public void createAccount(){ //IAccount account= new Account(accountNumber,party,amount) ; //daoService.create(); } /* (non-Javadoc) * @see service.IAccountService#removeAccount(business.IAccount) */ public void removeAccount(){ } /* (non-Javadoc) * @see service.IAccountService#addAccountEntry(business.IAccountEntry) */ @Override public void addAccountEntry(IAccountEntry accountEntry){ } /* (non-Javadoc) * @see service.IAccountService#removeAccountEntry(business.IAccountEntry) */ @Override public void removeAccountEntry(IAccountEntry accountEntry){ } /* (non-Javadoc) * @see service.IAccountService#deposit(business.IAccount, java.math.BigDecimal) */ @Override public void deposit(IAccount account, BigDecimal amount){ } /* (non-Javadoc) * @see service.IAccountService#withdraw(business.IAccount, java.math.BigDecimal) */ @Override public void withdraw(IAccount account, BigDecimal amount){ } /* (non-Javadoc) * @see service.IAccountService#getCurrentBalance() */ @Override public BigDecimal getCurrentBalance(){ return null; } /* (non-Javadoc) * @see service.IAccountService#findAccountsByParty(business.IParty) */ @Override public List&lt;IAccount&gt; findAccountsByParty(IParty party){ return null; } /* (non-Javadoc) * @see service.IAccountService#findAccountByAccountNumber(int) */ @Override public IAccount findAccountByAccountNumber(int accountNumber){ return null; } @Override public void removeAccount(IAccount account) { // TODO Auto-generated method stub } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload