Created
September 11, 2011 15:25
-
-
Save bivas/1209708 to your computer and use it in GitHub Desktop.
Adapter Pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.adapter; | |
public interface ComplexNumber { | |
double real(); | |
double imaginary(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.adapter; | |
public ComplexNumberAdapter implements ComplexNumber { | |
private final RealNumber realNumber; | |
public ComplexNumberAdapter(RealNumber realNumber) { | |
this.realNumber = realNumber; | |
} | |
@Override | |
public double real() { | |
return realNumber.value(); | |
} | |
@Override | |
public double imaginary() { | |
return 0; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.adapter; | |
public interface RealNumber { | |
double value(); | |
} | |
public final class Pi implements RealNumber { | |
@Override | |
public double value() { | |
return 3.14159; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment