Daily 2019-01-24
Daily
오전: cardgame step1 : 수정
피드백중에서 생각하고 고민할 부분에 대해서 남겨보자!
함수 하나라도 의도적으로 그 동작을 담당하는 클래스가 함수를 포함하도록 만드세요. main에서는 객체끼리 협력하도록만 구성하는거죠. 함수 단위보다 큰 객체 단위로 생각하는 연습을 하는 겁니다.
main.swift 파일에 이렇게 작성을 하였다.
func createRandomCard() -> Card {
let number = Number.allCases.randomElement() ?? .ace
let shape = Shape.allCases.randomElement() ?? .spades
return Card(number: number, shape: shape)
}
func main() {
let card = createRandomCard()
OutputView.output(card)
}
main()
그래서 이후 피드백 받고 수정한 부분
// main.swift
func main() {
let card = CardFactory.createRandomCard()
OutputView.output(card)
}
main()
//CardFactory.swift
struct CardFactory {
// 숫자와 모양을 랜덤으로 생성해주는 함수
static func createRandomCard() -> Card {
let number = Number.allCases.randomElement() ?? .ace
let shape = Shape.allCases.randomElement() ?? .spades
return Card(number: number, shape: shape)
}
}
변경하였다.
오후 : 디버깅 강의
Written on January 24, 2019