IMPLEMENTATION OF FAÇADE AND FACTORY
PATTERN
As explained façade pattern provides a unified interface to a set of interfaces in a subsystem. It defines a higher level interface that makes the subsystem easier to use.
In this project, it defines a high level
interface(BiddingFacade) representing a subsystem(Server) to be used by another
subsystem(Client). Server subsystem is defined using the following remote
methods(placeNurseTimeForBid, bidOnNurseTime,….). The class(BiddingFacadeImpl)
implements the interface(BiddingFacade).All the clients after getting remote
access to the server needs to communicate only through this class. Hence, we
achieve a unified interface to communicate with a server, and also a single
point through which all the requests can be funneled. Multiple implementations
of the façade can be provided, for example one which tracks all the changes
send by a user to the server, another façade can be implemented to monitor the
performance for each server call and so on. Façade pattern allows a lot of
extensibility
public
interface BiddingFacade {
public void placeNurseTimeForBid(Nurse
nurse);
public boolean isPatientNameUnique(String
patientName);
public void bidOnNurseTime(BidDetails
details);
public List getBidableNurseTimes();
public List getAllNurseTimes();
public Collection getAllBidDetails();
}
public
class BiddingFacadeImpl implements BiddingFacade {
public BiddingFacadeImpl() {
this.services =
Mediator.lookupBiddingServices();
}
public void bidOnNurseTime(BidDetails
details) {
try {
services.bidOnNurseTime(details);
} catch(RemoteException e) {
throw new
IllegalStateException(e.getMessage());
}
}
public List getAllNurseTimes() {
try {
return services.getAllNurseTimes();
} catch(RemoteException e) {
throw new
IllegalStateException(e.getMessage());
}
}
public List getBidableNurseTimes() {
try {
return
services.getBidableNurseTimes();
} catch(RemoteException e) {
throw new
IllegalStateException(e.getMessage());
}
}
public void placeNurseTimeForBid(Nurse
nurse) {
try {
services.placeNurseTimeForBid(nurse);
} catch(RemoteException e) {
throw new IllegalStateException(e.getMessage());
}
}
public boolean isPatientNameUnique(String
patientName) {
try {
return
services.isPatientNameUnique(patientName);
} catch(RemoteException e) {
throw new IllegalStateException(e.getMessage());
}
}
public Collection getAllBidDetails() {
try {
return services.getAllBidDetails();
} catch(RemoteException e) {
throw new
IllegalStateException(e.getMessage());
}
}
BiddingServices services = null;
}
As explained Factory Method Pattern define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. It provides a simple decision-making class that returns one of several possible subclasses of an abstract base class, depending on the data that are provided.
If we are unable to decide which
façade to be used(tracks
all the changes send by a user to the server or monitor the performance of the
server), a factory method pattern can be used to decide which class to
instantiate.
A factory pattern is implemented for this project to instantiate BiddingFacadeImpl class. The code is as follows.
public
class FaçadeFactory {
public static BiddingFacade createBiddingFacade() {
return new
BiddingFacadeImpl();
}
}