#1317 Special Case Pattern (#1624)

* #1317 Add Special Case Pattern

To focus on pattern itself, I implement DB and
maintenance lock by the singleton instance.

* #1317 Add special cases unit tests

Assert the logger output
(ref: https://stackoverflow.com/a/52229629)

* #1317 Add README.md

Add Special Case Pattern README

* #1317 Format: add a new line to end of file

Co-authored-by: Subhrodip Mohanta <subhrodipmohanta@gmail.com>
This commit is contained in:
ignite1771
2021-01-13 15:36:21 +08:00
committed by GitHub
parent bbc4fdfc24
commit dea7ecfb7a
21 changed files with 1084 additions and 0 deletions

View File

@ -0,0 +1,119 @@
@startuml
left to right direction
package com.iluwatar.specialcase {
class App {
- LOGGER : Logger {static}
+ App()
+ main(args : String[]) {static}
}
interface ApplicationServices {
+ loggedInUserPurchase(String, String) : ReceiptViewModel {abstract}
}
class ApplicationServicesImpl {
- domain : DomainServicesImpl
+ ApplicationServicesImpl()
- isDownForMaintenance() : boolean
+ loggedInUserPurchase(userName : String, itemName : String) : ReceiptViewModel
}
class Db {
- instance : Db {static}
- itemName2Product : Map<String, Product>
- user2Account : Map<User, Account>
- userName2User : Map<String, User>
+ Db()
+ findAccountByUser(user : User) : Account
+ findProductByItemName(itemName : String) : Product
+ findUserByUserName(userName : String) : User
+ getInstance() : Db {static}
+ seedItem(itemName : String, price : Double)
+ seedUser(userName : String, amount : Double)
}
class Account {
- amount : Double
+ Account(this$0 : Double)
+ getAmount() : Double
+ withdraw(price : Double) : MoneyTransaction
}
class Product {
- price : Double
+ Product(this$0 : Double)
+ getPrice() : Double
}
class User {
- userName : String
+ User(this$0 : String)
+ getUserName() : String
+ purchase(item : Product) : ReceiptDto
}
interface DomainServices {
}
class DomainServicesImpl {
+ DomainServicesImpl()
- purchase(user : User, account : Account, itemName : String) : ReceiptViewModel
+ purchase(userName : String, itemName : String) : ReceiptViewModel
}
class DownForMaintenance {
- LOGGER : Logger {static}
+ DownForMaintenance()
+ show()
}
class InsufficientFunds {
- LOGGER : Logger {static}
- amount : Double
- itemName : String
- userName : String
+ InsufficientFunds(userName : String, amount : Double, itemName : String)
+ show()
}
class InvalidUser {
- LOGGER : Logger {static}
- userName : String
+ InvalidUser(userName : String)
+ show()
}
class MaintenanceLock {
- LOGGER : Logger {static}
- instance : MaintenanceLock {static}
- lock : boolean
+ MaintenanceLock()
+ getInstance() : MaintenanceLock {static}
+ isLock() : boolean
+ setLock(lock : boolean)
}
class MoneyTransaction {
- amount : Double
- price : Double
+ MoneyTransaction(amount : Double, price : Double)
}
class OutOfStock {
- LOGGER : Logger {static}
- itemName : String
- userName : String
+ OutOfStock(userName : String, itemName : String)
+ show()
}
class ReceiptDto {
- LOGGER : Logger {static}
- price : Double
+ ReceiptDto(price : Double)
+ getPrice() : Double
+ show()
}
interface ReceiptViewModel {
+ show() {abstract}
}
}
User --+ Db
Product --+ Db
MaintenanceLock --> "-instance" MaintenanceLock
Db --> "-instance" Db
ApplicationServicesImpl --> "-domain" DomainServicesImpl
Account --+ Db
ApplicationServicesImpl ..|> ApplicationServices
DomainServicesImpl ..|> DomainServices
DownForMaintenance ..|> ReceiptViewModel
InsufficientFunds ..|> ReceiptViewModel
InvalidUser ..|> ReceiptViewModel
OutOfStock ..|> ReceiptViewModel
ReceiptDto ..|> ReceiptViewModel
@enduml

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 KiB