Created
November 20, 2018 16:04
-
-
Save Stefku/31966f2e59a31ae42c018ed628ecfd9c to your computer and use it in GitHub Desktop.
Attempt to Specification Pattern with encapsulation
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 ch.sbb.touri.zusatzinfo; | |
interface Queryable { | |
boolean satisfies(Querying querying); | |
} | |
interface Querying { | |
boolean calculateWithValue(long value); | |
} | |
public class Product implements Queryable { | |
private final long price; | |
public Product(long price) { | |
this.price = price; | |
} | |
public boolean satisfies(Querying querying) { | |
return querying.calculateWithValue(price); | |
} | |
} | |
abstract class Query implements Querying { | |
public boolean isFullfilledBy(Queryable queryable) { | |
return queryable.satisfies(this); | |
} | |
public abstract boolean calculateWithValue(long value); | |
} | |
class LessThanQuery extends Query { | |
private final long border; | |
LessThanQuery(long border) { | |
this.border = border; | |
} | |
@Override | |
public boolean calculateWithValue(long value) { | |
return border < value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment