Skip to content

Instantly share code, notes, and snippets.

class LoyaltyCardService {
// constructor removed for brevity's sake
void addPoints(int id, int points) {
LoyaltyCard card = //... find card by id in db
card.addPoints(points);
// persist the LoyaltyCard
}
void removePoints(int id, int points) {
class LoyaltyCard {
private int id;
private int balance;
private int cardType;
// getter, constructor removed for brevity's sake
void addPoints(int points) {
int extraPoints = 0;
if (cardType == 1) extraPoints = 1;
class LoyaltyCardService {
// constructor removed for brevity's sake
void addPoints(int id, int points) {
LoyaltyCard card = //... find card by id in db
card.balance += points;
// persist the LoyaltyCard
}
void removePoints(int id, int points) {
class LoyaltyCard {
private int id;
private int balance;
// getter, constructor removed for brevity's sake
}
class Garage {
Plane plane;
public void leaveGarage() {
...
plane.isPilotAllowedToFly(); // Not Allowed!! ... because
...
}
}
APIClient client = anAPIClientBuilder()
.withHost("..") // Rule #4
.withAppKey("..") // Rule #4
.withSecretKey("..") // Rule #4
.build();
car.getOwner().getAddress().getStreet();
// or
Owner owner = car.getOwner();
Address ownerAddress = owner.getAddress();
Street ownerStreet = ownerAddress.getStreet();
public class DBConnection {
private static int MAX_CONNECTION = 1;
private DbConnectionFactory factory;
public void close() {
...
clear(); // Allowed Rule #1
...
}
FROM nginx:1.16.0-alpine
COPY --from=builder /dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
FROM openjdk:8-jdk-alpine
COPY --from=MAVEN_TOOL_CHAIN /tmp/target/io-app-service*.jar app.jar
ENV JAVA_OPTS=""
EXPOSE 8080
ENTRYPOINT exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar