October 2017
Intermediate to advanced
396 pages
10h 2m
English
Let's try another method for dependent objects using the Factory pattern. This design pattern is based on the GOF factory design pattern to create object instances by using a factory method. So this method actually centralizes the use of the new operator. It creates the object instances based on the information provided by the client code. This pattern is widely used in the dependency injection strategy.
TransferService using factory helper:
package com.packt.chapter1.bankapp.transfer;
public class TransferService {
private AccountRepository accountRepository;
public TransferService() {
this.accountRepository = AccountRepositoryFactory.getInstance("jdbc"); } public void transferMoney(Account ...Read now
Unlock full access