mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-18 02:59:19 +00:00
docs: update special case
This commit is contained in:
@@ -26,6 +26,8 @@ package com.iluwatar.specialcase;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* DB class for seeding user info.
|
||||
@@ -119,17 +121,11 @@ public class Db {
|
||||
/**
|
||||
* User class to store user info.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class User {
|
||||
|
||||
private String userName;
|
||||
|
||||
public User(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
private final String userName;
|
||||
|
||||
public ReceiptDto purchase(Product item) {
|
||||
return new ReceiptDto(item.getPrice());
|
||||
@@ -139,13 +135,11 @@ public class Db {
|
||||
/**
|
||||
* Account info.
|
||||
*/
|
||||
public class Account {
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public static class Account {
|
||||
|
||||
private Double amount;
|
||||
|
||||
public Account(Double amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
private final Double amount;
|
||||
|
||||
/**
|
||||
* Withdraw the price of the item from the account.
|
||||
@@ -159,25 +153,15 @@ public class Db {
|
||||
}
|
||||
return new MoneyTransaction(amount, price);
|
||||
}
|
||||
|
||||
public Double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Product info.
|
||||
*/
|
||||
public class Product {
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public static class Product {
|
||||
|
||||
private Double price;
|
||||
|
||||
public Product(Double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public Double getPrice() {
|
||||
return price;
|
||||
}
|
||||
private final Double price;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.specialcase;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -35,6 +36,8 @@ public class MaintenanceLock {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MaintenanceLock.class);
|
||||
|
||||
private static MaintenanceLock instance;
|
||||
|
||||
@Getter
|
||||
private boolean lock = true;
|
||||
|
||||
/**
|
||||
@@ -49,10 +52,6 @@ public class MaintenanceLock {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public boolean isLock() {
|
||||
return lock;
|
||||
}
|
||||
|
||||
public void setLock(boolean lock) {
|
||||
this.lock = lock;
|
||||
LOGGER.info("Maintenance lock is set to: {}", lock);
|
||||
|
||||
@@ -24,16 +24,14 @@
|
||||
*/
|
||||
package com.iluwatar.specialcase;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* Represents the money transaction taking place at a given moment.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class MoneyTransaction {
|
||||
|
||||
private Double amount;
|
||||
private Double price;
|
||||
|
||||
public MoneyTransaction(Double amount, Double price) {
|
||||
this.amount = amount;
|
||||
this.price = price;
|
||||
}
|
||||
private final Double amount;
|
||||
private final Double price;
|
||||
}
|
||||
|
||||
@@ -24,26 +24,22 @@
|
||||
*/
|
||||
package com.iluwatar.specialcase;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Receipt view representing the transaction recceipt.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class ReceiptDto implements ReceiptViewModel {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ReceiptDto.class);
|
||||
|
||||
private final Double price;
|
||||
|
||||
public ReceiptDto(Double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public Double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
LOGGER.info(String.format("Receipt: %s paid", price));
|
||||
|
||||
Reference in New Issue
Block a user