Skip to content

Instantly share code, notes, and snippets.

@Stefku
Created November 20, 2018 16:04
Show Gist options
  • Save Stefku/31966f2e59a31ae42c018ed628ecfd9c to your computer and use it in GitHub Desktop.
Save Stefku/31966f2e59a31ae42c018ed628ecfd9c to your computer and use it in GitHub Desktop.
Attempt to Specification Pattern with encapsulation
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