-
Notifications
You must be signed in to change notification settings - Fork 170
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
Week3 [STEP 1] cherrishRed #3
Week3 [STEP 1] cherrishRed #3
Conversation
2번에 대한 답은 제가 하겠습니다! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cherrishRed
요구사항 진행하시느라 고생 많으셨습니다! 🥳
내용이 점점 복잡해질겁니다. 너무 조바심 내지 마시고 천천히 하시면 됩니다. 지금도 충분히 잘 하고 계시니까요. 열심히 해내주시는 모습을 보고 있으니 저도 자극을 받네요!
우선 코드에 대해서 궁금한 점이 있어서 코멘트 달아놨고, 조언이 필요하다고 하신 부분에 대해서 약간의 의견을 남겨보자면,
enum
타입은 앞으로 정해져서 값이 추가 되거나 변경 될 일 없는 요일 등에 쓰는 것이라 이해 했습니다.
저는 커피 메뉴는 유동적인 것이라 생각했는데, 다른 구현 방법을 발견하지 못해 (그리고 문제에 명시되어 있어) enum 을 사용했는데요. 변경 여부가 있는 값은 무엇으로 지정하는 것이 좋을까요?
열거형이 변경될 일이 없는 것에 사용하는 것이라고 이해한 이유가 뭘까요? 🤔
타입 프로퍼티, 타입 메소드 에 관한 부분을 공부 하였는데요.
인스턴스로 접근하지 않고 클래스 구조체 그 자체로 접근한다. 는 것은 알았지만 어떤 상황에서 이 문법이 필요한 것 인지 감이 안 옵니다.🥲
말 그대로 타입 자체와 관련된 값이죠. 타입 프로퍼티는 다른 문법과 마찬가지로 많은 곳에서 쓰일 수 있습니다. 우선 예시 코드를 작성해볼게요.
struct WooriBank {
static let dollarExchangeRate: Double = 1200
// Code...
func exchangeToDollar(_ won: Int) -> Double {
return Double(won) / Self.dollarExchangeRate
}
}
사실 구조체 자체를 은행
으로 잡았으면, 변경 시 환율이 조금씩 달라질 수 있겠죠? 하지만 우리은행
으로 만들었기 때문에, 우리은행
자체의 환율은 모두 동일합니다. 즉, 우리은행
이라는 타입과 직접적으로 연결된 값이죠. 도움이 됐으면 좋겠습니다. 🙂 더 궁금하신 게 있다면 DM 주세요!
@@ -8,5 +8,11 @@ | |||
|
|||
import Foundation | |||
|
|||
print("Hello, World!") | |||
struct Person { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
클래스가 아닌, 구조체로 정의한 이유가 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
클래스와 구조체를 비교하여 보았을 때, 구조체는 값타입이고 클래스는 참조타입인데 클래스가 참조를 하기 때문에 메모리 용량이 더 많이 차지 한다고 들었습니다. 그리고 아직은 상속을 사용할 이유가 없어 보여서 클래스를 쓸 이유가 없다고 생각했습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확실히 성능면에서 차이가 있기도 하고, 상속 때문에 클래스를 사용하는 경우도 있긴 하지만, 꼭 그런 이유 때문에 구조체를 사용하는 것은 취지에 맞지 않는 것 같네요. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 그 타입들을 조금 더 공부해야 할 것 같습니다. 🥲
문법 자체는 알겠으나, 사용처 등의 이유를 붙이기에 아직 부족한 것 같네요.
제가 step3를 하면서도 이부분에 대해 다시 고민 해보겠습니다.
CodeStarterCamp_Week3/main.swift
Outdated
@@ -8,5 +8,11 @@ | |||
|
|||
import Foundation | |||
|
|||
print("Hello, World!") | |||
struct Person { | |||
var name: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이름을 변수로 선언하신 이유가 있나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
생각해보니 이름이 바뀔 일이 없는데 let 을 쓰는게 더 맞았을 것 같네요
CodeStarterCamp_Week3/main.swift
Outdated
var menuBoard: [String: Int] = [:] | ||
menuBoard["espresso"] = 3000 | ||
menuBoard["americano"] = 4000 | ||
menuBoard["cafeLatte"] = 5000 | ||
menuBoard["cafeMocha"] = 5000 | ||
menuBoard["flatWhite"] = 5000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
원시값은 중복이 될 수 없어서 딕셔너리로 선언했다고 하셨는데, 다른 방법은 없을까요? 지금은 Coffee
라는 타입과 연관이 없어 보입니다. 열거형에는 case
만 사용할 수 있을까요? ㅎㅎ 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 이부분에 대해서 많은 고민을 하고 문서도 여럿 읽어 보느라 시간이 좀 걸렸습니다.
case 말고도
- indirect case 를 사용해 (재귀 열거형 맞나요?) case 의 값을 매개변수로 받는 (표현이 적당한지는 모르겠으나) 열거형을 만들 수도 있고
- subscript 문법을 이용할 수도 있고
- 연산 프로퍼티를 가질 수 있습니다.
dictionary 자체를 enum 안에 넣어 보려고 했지만 enum 은 저장 프로퍼티를 가질수 없었습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
많은 걸 알아보셨네요! 👏 그런데 너무 깊게 가셨어요... 그리고 해당 구현을 위해 indirect case를 사용하는 건 해당 문법의 취지에 맞지 않다고 생각합니다. 😯 그리고 서브스크립트 문법도 아직은 어려울 수 있으니, 연산 프로퍼티로 한 번 구현해보면 좋겠어요 ㅎㅎ
CodeStarterCamp_Week3/main.swift
Outdated
var menu: [String: Int] = menuBoard | ||
var pickUpTable: String? = nil | ||
|
||
init(owner brista: Person){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오너가 꼭 바리스타가 아닐 수도 있지 않을까요? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그렇네요. 이부부은 조금 더 좋은 네이밍을 골라보도록 하겠습니다.
CodeStarterCamp_Week3/main.swift
Outdated
self.brista = brista | ||
} | ||
|
||
mutating func takeAOrder(coffee: Coffee) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mutating
키워드는 언제 필요하고, 왜 필요한가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
구조체 안에서 프로퍼티 값을 변경하고자 할 때 사용한다고 공부했습니다.
CodeStarterCamp_Week3/main.swift
Outdated
print(salesRevenue) | ||
} | ||
} | ||
func makeACoffeec(coffee: String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오타가 있네요!
그리고 위의 takeAOrder
와 마찬가지고 관사를 넣어주셨네요. 혹시 이유가 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네 오타 수정하겠습니다.
커피 하나를 주문 한다고 생각해서(매개변수를 하나만 받으니까) a 를 넣었는데 생각해보니 coffees 가 더 나은 표현인 것 같습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 질문드리는 것은 틀려서 질문하는 게 아닙니다! 질문의 의도로 받아주시면 좋겠어요.
보통 네이밍에서는 단수와 복수를 구분할 때 복수형만으로도 구분할 수 있기 때문에 a
또는 an
과 같은 관사를 안쓰는게 개인적으로 더 깔끔할 것 같아요.
그리고 the
같은 정관사는 상황에 따라서 사용할 수도 있을 것 같구요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 질문드리는 것은 틀려서 질문하는 게 아닙니다! 질문의 의도로 받아주시면 좋겠어요.
넵. 야곰님이 세션에서 말해주신 대로 정답을 원하는 습관을 고쳐야 되는데... 어렵네요ㅎㅎ😗
안그래도 저 a를 대소문자 처리를 어떻게 해야하는지가 고민이었는데 (가독성 이유로),
좋은 조언 감사합니다.
CodeStarterCamp_Week3/main.swift
Outdated
init(staff brista: Person) { | ||
self.brista = brista | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
꼭 사장님이 바리스타일 필요는 없죠! 👍
+ 이 부분이 없으면 어떻게 될까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
staff 를 와일드 카드로 처리하면 전달인자 레이블이 생략되고, 아예 생략할 경우 brista 가 전달인자 레이블이자 매개변수 이름이 됩니다.
init 을 생략하면 brista 에 기본값 설정을 해주지 않아서 오류가 납니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아 staff에 왜 하이라이트가... 😓
저는 이니셜라이저 자체가 없는 상황을 이야기 하고 싶었어요. ㅎㅎ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아, 제가 질문을 잘못 이해 했네요...
init 을 생략하면 brista 에 기본값 설정을 해주지 않아서 오류가 나서
brista 에 기본값을 주거나,
옵셔널 타입으로 지정 해주면 좋을 것 같습니다.
@Journey36 우선 주신 코멘트에 답을 하자면:
월요일에 야곰 피드백 세션을 들을 때 그렇게 말씀해 주셔서, 추가 될 수 도 있는 것을 enum으로 하는 것은 좋지 못하다.
리펙토링시 고민한 점 enum 에 대해서 공부해보고 연산 프로퍼티를 쓰기로 결정했습니다. 그런데 다시 요구 사항을 읽어보니 coffeShop 자체에서 메뉴판이라는 값을 가져야 되더군요. 아, 그리고 Happy Christmas!🎄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cherrishRed
레드님! 리팩토링하느라 고생하셨습니다. 많은 고민이 있었네요. 그리고 그 고민이 점점 깊어져가는 것 같습니다. 🙂 코멘트 확인 후 답 남겨 주시면, 머지하겠습니다. 부족한 부분은 다음 스텝에서 확인하겠습니다. 고생하셨어요!
고민했던 점에 남겨주신 메뉴판의 타입은 Coffee
타입으로 받으면 되지 않을까요? 이미 매개변수로 받으셨던데.. ㅎㅎ
그리고 저번에 예시를 들었던 부분에 대해서 코멘트 남겨주셨는데요.
제가 예시를 들어주신 코드를 잘 이해하지 못한 것 같아요.😂
구조체 이름을 은행으로 잡는 것과 우리은행 으로 잡았을 때 달라질 것이 있나요?
아니면 mutating 을 사용하더라도 접근을 못하게 하려는 것일 까요?
죄송합니다. 제가 예시를 잘 못드는 편이라 ㅎㅎ... 😭아무튼 타입 프로퍼티와 타입 메소드에 관한 질문이었죠. 타입과 직접적인 연관이 있는 프로퍼티 또는 메소드임을 강조하기 위해서 그런 예시를 들었어요. 만약 은행
으로 구조체를 만들면 그 인스턴스는 농협 은행
이 될 수도, 국민 은행
또는 기업 은행
등이 될수 있겠죠? 각 은행마다 환전을 할 때 환율을 다르게 책정하는 걸로 알고있어요. 그런데 만약 우리 은행
이라고 타입을 지정하면, 우리 은행
의 환율은 전국 우리 은행
이 모두 다 같다는 거죠. 그렇게 인스턴스와 관계없이 타입과 직접적인 값을 나타낼 때 타입 프로퍼티나 메소드를 사용한다. 를 설명하고 싶어서 예시를 들었습니다.. 미천한 저의 예시 때문에 혹시 그래도 이해가 안가신다면 DM 남겨주십셔.. 😢
그리고 레드님도 메리 크리스마스! 🎄🎅
var cost: Int { | ||
switch self { | ||
case .espresso: | ||
return 3000 | ||
case .americano: | ||
return 4000 | ||
case .cafeLatte: | ||
return 5000 | ||
case .cafeMocha: | ||
return 5000 | ||
case .flatWhite: | ||
return 5000 | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋네요! 👍
@Journey36
들어주신 은행 예시 이해했습니다!🥳🥳🥳 |
@Journey36
안녕하세요 글렌!
이론이 너무 어려워서 공부하다 보니 PR 이 늦었네요.
Step1 PR 보냅니다.
고민되었던 점
메뉴 와 가격이 담긴 메뉴판을 어떻게 구현할지 고민했습니다.
처음엔 enum 타입의 rawValue 를 가격으로 하려고 하였으나 같은 값을 가질 수 없는 특성으로 선택하지 않았고
[메뉴: 가격]이 담긴 dictionary 로 구현 하였습니다.
그러다 보니 일일이 값을 넣어주게 되었습니다.
라고 하셨는데, 그 전에 Store 타입을 생성하라는 안내문에 없어서 Store 을 CoffeeShop 으로 받아들여서 작업하였습니다.
만약, Store 타입을 생성하라는 의도를 제가 잘못 이해한 것이라면 알려주세요.
조언을 얻고 싶은 부분
메뉴판 구현
enum 타입은 앞으로 정해져서 값이 추가 되거나 변경 될 일 없는 요일 등에 쓰는 것이라 이해 했습니다.
저는 커피 메뉴는 유동적인 것이라 생각했는데, 다른 구현 방법을 발견하지 못해 (그리고 문제에 명시되어 있어) enum 을 사용했는데요.
변경 여부가 있는 값은 무엇으로 지정하는 것이 좋을 까요?
static
타입 프로퍼티, 타입 메소드 에 관한 부분을 공부 하였는데요.
인스턴스로 접근하지 않고 클래스 구조체 그 자체로 접근한다. 는 것은 알았지만.
어떤 상황에서 이 문법이 필요한 것 인지 감이 안 옵니다.🥲