Skip to Main Content
Design Patterns and Best Practices in Java
book

Design Patterns and Best Practices in Java

by Kamalmeet Singh, Adrian Ianculescu, Lucian-Paul Torje
June 2018
Intermediate to advanced content levelIntermediate to advanced
280 pages
7h 46m
English
Packt Publishing
Content preview from Design Patterns and Best Practices in Java

Examples

The following code simulates the use of a PS/2 keyboard in a USB bus. It defines a PS/2 keyboard (adaptee), a USB device interface (target), a PS2ToUSBAdapter (adapter), and the wires to link in order to make the device work:

package gof.structural.adapter;import java.util.Arrays;import java.util.Collections;import java.util.List;class WireCap {  WireCap link = WireCap.LooseCap;  private Wire wire;  publicstatic WireCap LooseCap = new WireCap(null);  public WireCap(Wire wire)   {    this.wire = wire;   }  publicvoid addLinkTo(WireCap link)   {    this.link = link;  }  public Wire getWire()   {    return wire;  }  public String toString()   {    if (link.equals(WireCap.LooseCap))    return "WireCap belonging to LooseCap"; return "WireCap belonging to " + wire ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Practical Design Patterns for Java Developers

Practical Design Patterns for Java Developers

Miroslav Wengner
Java Design Patterns

Java Design Patterns

Vaskaran Sarcar

Publisher Resources

ISBN: 9781786463593Supplemental Content