This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Imagine supporting two windowing environments, Microsoft Windows�and the X Window System. Create an Abstract Factory class WindowFactory defining methods like #createButton. Add subclasses MSWindowFactory and XWindowFactory which implement #createButton to answer instances of MSButton or XButton respectively. A window painter can then be given an instance of MSWindowFactory or XWindowFactory. Sending it the #createButton message will result in an instance of MSButton or Xbutton. Assuming they respond to the same protocol, the client can remain ignorant of the class of the resultant button. Abstarct Factory Class: WindowFactory FactoryMethod(s): newWindow() which will return either MSWindowFactory or XWindowFactory. and createButton().