June 2018
Intermediate to advanced
280 pages
7h 46m
English
The following code presents an email client that makes use of an implementation based on the running platform. It can be enhanced with a factory method pattern to create the specific platform implementation:
package gof.structural.bridge;publicclass Main{ publicstaticvoid main (String[] args) { new AllMessageClient(new WindowsImplementation()) .sendMessageToAll("abc@gmail.com", "Test"); }}interface PlatformBridge { publicvoid forwardMessage(String msg);}
PlatformBridge is our implementation abstraction class. It specifies what each implementation needs to offer —in our case, to forward a message given by text. Both the following implementations, Windows, and POSIX, know how to do the task:
class WindowsImplementation implements ...
Read now
Unlock full access