Façade Pattern: used to make a single class represent an entire subsystem
Façade
pattern defines a high level interface representing a subsystem(Server)
to be used by another subsystem(Client). By doing this 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 AuctionFacade {
public void placeItemForBid(Item item);
public boolean isItemNameUnique(String itemName);
public void bidOnItem(BidDetails details);
public List getBidableItems();
public List getAllItems();
public Collection getAllBidDetails();
public void
lock(Item item);
public void unLock(Item item);
}
public class AuctionFacadeImpl
implements AuctionFacade {
public AuctionFacadeImpl() {
this.services =
Mediator.lookupAuctionServices();
}
public void bidOnItem(BidDetails details) {
try {
services.bidOnItem(details);
} catch(RemoteException e) {
throw new IllegalStateException(e.getMessage());
}
}
public List getAllItems() {
try {
return services.getAllItems();
} catch(RemoteException e) {
throw new IllegalStateException(e.getMessage());
}
}
public List getBidableItems() {
try {
return services.getBidableItems();
} catch(RemoteException e) {
throw new IllegalStateException(e.getMessage());
}
}
public void placeItemForBid(Item item) {
try {
System.out.println("In facade adding item: "+item);
services.placeItemForBid(item);
} catch(RemoteException e) {
throw new IllegalStateException(e.getMessage());
}
}
public boolean isItemNameUnique(String itemName) {
try {
return services.isItemNameUnique(itemName);
} catch(RemoteException e) {
throw new IllegalStateException(e.getMessage());
}
}
public Collection getAllBidDetails() {
try {
return services.getAllBidDetails();
} catch(RemoteException e) {
throw new IllegalStateException(e.getMessage());
}
}
public void
lock(Item item) {
try {
services.lock(item);
} catch(RemoteException e) {
throw new IllegalStateException(e.getMessage());
}
}
public void unLock(Item item) {
try {
services.unLock(item);
} catch(RemoteException e) {
throw new IllegalStateException(e.getMessage());
}
}
AuctionServices
services = null;
}
Factory Pattern: 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
And also a Factory is implemented for this project to create the facades. It’s based on the factory Pattern. The code is as follows.