Object Assembling
Adapter
// Target interface
interface Target {
void request();
}
// Adaptee (the class with an incompatible interface)
class Adaptee {
void specificRequest() {
System.out.println("Adaptee's specific request");
}
}
// Adapter class that implements the Target interface and delegates requests to the Adaptee
class Adapter implements Target {
private Adaptee adaptee;
public Adapter(Adaptee adaptee) {
this.adaptee = adaptee;
}
@Override
public void request() {
adaptee.specificRequest();
}
}
// Client code
public class Main {
public static void main(String[] args) {
// Create an Adaptee object
Adaptee adaptee = new Adaptee();
// Create an Adapter object and pass the Adaptee to it
Target adapter = new Adapter(adaptee);
// Call the request method of the Target interface
adapter.request();
}
}
Bridge
Composite
Decorator
Facade
Flyweight
Proxy
Last updated