Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step3 : 업무 중 대기 (리나) #19

Merged
merged 21 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e7669df
Feat: HeadOffice 생성
lina0322 Jan 9, 2021
e0a49de
Feat: DashBoard 생성
lina0322 Jan 9, 2021
dfc7c4d
Remove: Teller.workingHours
lina0322 Jan 9, 2021
dd1f8f1
Feat: 대출심사 queue구현 및 시간 확인을 위해, 시간 출력
lina0322 Jan 9, 2021
50568c6
Refactor: priority와 businessType 랜덤 방식 변경
lina0322 Jan 9, 2021
45f521b
Remove: sortClientByPriority하고, Clients 정렬 방식 변경
lina0322 Jan 9, 2021
aef2237
Merge
lina0322 Jan 9, 2021
e739d65
Merge: Step1 리뷰 반영
lina0322 Jan 10, 2021
032fca2
Refactor: main의 private 제거
Jan 11, 2021
8d12b14
Merge: step2 수정
lina0322 Jan 12, 2021
67e050a
Refactor: 접근제한자 수정, 필요없는 self제거, 복잡한 구문 수정 등
lina0322 Jan 12, 2021
5ec44df
Style: 불필요한 공백 제거
lina0322 Jan 12, 2021
3fda98b
Style: 불필요한 공백 제거
lina0322 Jan 12, 2021
b8a57aa
Refactor: queue를 let으로 선언
lina0322 Jan 12, 2021
2839647
Refactor: BankError -> StringFormattingError으로 변경
lina0322 Jan 12, 2021
37bce73
Add: Clients 파일
lina0322 Jan 12, 2021
5849c49
Add: enum안에 있던 type들 각각의 파일로 생성
lina0322 Jan 12, 2021
4b3a68b
Refactor: operateBank -> open
lina0322 Jan 12, 2021
95adaf9
Feat: teller init을 Tellers를 생성하고 거기서 실행
lina0322 Jan 12, 2021
4c547e8
Refactor: closeBank -> resetFinishedClientCount 로 변경
lina0322 Jan 12, 2021
04d6910
Feat: handleLoan을 reviewDocument, sendDocumentToHeadOffice, finishLoa…
lina0322 Jan 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Bank.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ final class Bank {
var isContinue = true

while isContinue {
for teller in self.tellers {
if self.clients.count == 0 {
for teller in tellers {
if clients.count == 0 {
Comment on lines -37 to +32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self. 를 지운 이유는 무엇인가요?

isContinue = false
break
}
if teller.isNotWorking {
let client = clients.removeFirst()
teller.handleBusiness(for: client, withDispatchGroup: dispatchGroup)
self.finishedClientCount += 1
finishedClientCount += 1
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
4CB8E9BB25A998E300C021F6 /* HeadOffice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB8E9BA25A998E300C021F6 /* HeadOffice.swift */; };
4CB8E9C425A99CE000C021F6 /* Dashboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB8E9C325A99CE000C021F6 /* Dashboard.swift */; };
4CDDB11825A422B700EDC9CE /* Teller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CDDB11725A422B700EDC9CE /* Teller.swift */; };
4CDDB11B25A422CD00EDC9CE /* Client.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CDDB11A25A422CD00EDC9CE /* Client.swift */; };
Expand All @@ -28,6 +29,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
4CB8E9BA25A998E300C021F6 /* HeadOffice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadOffice.swift; sourceTree = "<group>"; };
4CB8E9C325A99CE000C021F6 /* Dashboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dashboard.swift; sourceTree = "<group>"; };
4CDDB11725A422B700EDC9CE /* Teller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Teller.swift; sourceTree = "<group>"; };
4CDDB11A25A422CD00EDC9CE /* Client.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Client.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -67,6 +69,7 @@
C7694E78259C3EC00053667F /* BankManagerConsoleApp */ = {
isa = PBXGroup;
children = (
4CB8E9BA25A998E300C021F6 /* HeadOffice.swift */,
4CB8E9C325A99CE000C021F6 /* Dashboard.swift */,
C7D65D1A259C8190005510E0 /* Bank.swift */,
4CDDB11725A422B700EDC9CE /* Teller.swift */,
Expand Down Expand Up @@ -135,6 +138,7 @@
buildActionMask = 2147483647;
files = (
C7694E7A259C3EC00053667F /* main.swift in Sources */,
4CB8E9BB25A998E300C021F6 /* HeadOffice.swift in Sources */,
C7D65D1B259C8190005510E0 /* Bank.swift in Sources */,
4CDDB11E25A422EF00EDC9CE /* Enum.swift in Sources */,
4CDDB11B25A422CD00EDC9CE /* Client.swift in Sources */,
Expand Down
3 changes: 2 additions & 1 deletion BankManagerConsoleApp/BankManagerConsoleApp/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ struct Clients {
guard let businessType = BusinessType.allCases.randomElement(), let priority = Client.Priority.allCases.randomElement() else {
return
}
list.append(Client(waitingNumber: waitingNumber, businessType: businessType, priority: priority))
let clinet = Client(waitingNumber: waitingNumber, businessType: businessType, priority: priority)
list.append(clinet)
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

보통 하나의 파일에 하나의 타입만을 저장합니다.
Clients 를 따로 파일로 빼내는 것은 어떨까요?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct Dashboard {

static func printCloseMessage(_ count: Int, _ time: TimeInterval?) {
guard let time = time else {
print("\(BankError.unknown)")
print("\(StringFormattingError.unknown)")
return
}
let message = String(format: Message.close, count, time)
Expand Down
6 changes: 4 additions & 2 deletions BankManagerConsoleApp/BankManagerConsoleApp/Enum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ enum Message {
static let close = "업무가 마감되었습니다. 오늘 업무를 처리한 고객은 총 %d명이며, 총 업무시간은 %.2f초입니다."
static let tellerStart = "%d번 %@고객 %@업무 시작"
static let tellerFinish = "%d번 %@고객 %@업무 완료"
static let loanStart = "%d번 %@고객 %@심사 시작"
static let loanFinish = "%d번 %@고객 %@심사 완료"
}

enum BusinessType: CaseIterable, CustomStringConvertible {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

보통 하나의 타입을 하나의 파일에 저장합니다. enum 들도 따로 파일로 저장하는 건 어떨까요?

Expand All @@ -33,7 +35,7 @@ enum BusinessType: CaseIterable, CustomStringConvertible {
case .deposit:
return 0.7
case .loan:
return 1.1
return 0.3
}
}

Expand All @@ -47,7 +49,7 @@ enum BusinessType: CaseIterable, CustomStringConvertible {
}
}

enum BankError: Error, CustomStringConvertible {
enum StringFormattingError: Error, CustomStringConvertible {
case wrongInput
case unknown

Expand Down
22 changes: 22 additions & 0 deletions BankManagerConsoleApp/BankManagerConsoleApp/HeadOffice.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// HeadOffice.swift
// BankManagerConsoleApp
//
// Created by 임리나 on 2021/01/09.
//

import Foundation

final class HeadOffice {
static let shared = HeadOffice()
private let neededTimeToJudgeLoan: TimeInterval = 0.5
let loanQueue: DispatchQueue = DispatchQueue(label: "HeadOffice")

private init() {}

func judgeLoan(for client: Client) {
Dashboard.printStatus(for: client, about: Message.loanStart)
Thread.sleep(forTimeInterval: self.neededTimeToJudgeLoan)
Dashboard.printStatus(for: client, about: Message.loanFinish)
}
}
32 changes: 28 additions & 4 deletions BankManagerConsoleApp/BankManagerConsoleApp/Teller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

final class Teller {
private var windowNumber: Int
var workingQueue: DispatchQueue
let workingQueue: DispatchQueue
private var isWorking: Bool = false
var isNotWorking: Bool {
return !isWorking
Expand All @@ -24,10 +24,34 @@ final class Teller {
isWorking = true

workingQueue.async(group: group) {
Dashboard.printStatus(for: client, about: Message.tellerStart)
Thread.sleep(forTimeInterval: client.businessType.neededTime)
Dashboard.printStatus(for: client, about: Message.tellerFinish)
switch client.businessType {
case .deposit:
self.handleDeposit(for: client)
case .loan:
self.handleLoan(for: client)
}
self.isWorking = false
}
}

func handleDeposit(for client: Client) {
Dashboard.printStatus(for: client, about: Message.tellerStart)
Thread.sleep(forTimeInterval: client.businessType.neededTime)
Dashboard.printStatus(for: client, about: Message.tellerFinish)
}


func handleLoan(for client: Client) {
let semaphore = DispatchSemaphore(value: 0)

Dashboard.printStatus(for: client, about: Message.tellerStart)
Thread.sleep(forTimeInterval: client.businessType.neededTime)
HeadOffice.shared.loanQueue.async {
HeadOffice.shared.judgeLoan(for: client)
semaphore.signal()
}
semaphore.wait()
Thread.sleep(forTimeInterval: client.businessType.neededTime)
Dashboard.printStatus(for: client, about: Message.tellerFinish)
}
}
4 changes: 2 additions & 2 deletions BankManagerConsoleApp/BankManagerConsoleApp/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ func main() {
Dashboard.printMenu()

guard let input = readLine(), let command = Menu(rawValue: input) else {
print("\(BankError.wrongInput)")
print("\(StringFormattingError.wrongInput)")
continue
}

switch command {
case .start:
let randomNumber = Int.random(in: minClientCount...maxClientCount)
let clients = Clients.init(count: randomNumber)
let clients = Clients(count: randomNumber)
bank.operateBank(teller: tellerCount, client: clients.list)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bank.operateBank 라는 부분은 조금 어색한 것 같네요.
은행이 은행을 운용한다는 뜻으로 보이는데 조금 개선해볼 수 있을까요?

case .end:
isContinue = false
Expand Down