BLU
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    JuiceMaker [STEP 1] Logan, Blue 안녕하세요, 웨더! (@sungpyo) 쥬스메이커 프로젝트를 진행하게 된 **Team Bu-Lo**의 Blue & Logan입니다! ✋ 코드 작성 전 생각하고 코딩하기 위해 노력하고, 많이 얘기 나누어 보았습니다. 아직 많이 어설프겠지만 피드백 주신 내용 열심히 고민하고 학습하여 반영하겠습니다 😆 리뷰 감사드립니다!💙 새해 복 많이 받으세요! 🥰 --- ## ✅ 요구사항 분석 및 구현사항 **Step 1 쥬스 메이커 타입 정의** - [x] FruitStore 타입 정의 - [x] 관리하는 과일: 딸기, 바나나, 파인애플, 키위, 망고 - [x] 과일의 초기 재고: 10개 - [x] 과일 수량변경 기능 - [x] JuiceMaker 타입 정의 - [x] 레시피에 맞춰 과일주스 제조 - [x] 과일의 재고가 부족하면 쥬스 제조 불가 - [x] FruitStore를 소유하고 있음 ## 🗝️ 학습 키워드 - string.index - enum - rawValue의 사용 - Singleton - protocol 의존성 주입 **(학습 필요)** ## ☄️ 고민과 해결 1. **`FruitStore`는 왜 class로 구현되어 있었을까?** 과제를 처음 받았을 때 `class FruitStore {}` 형태로 구현이 되어있는 것을 보고 **singleton**으로 구현할 것을 의도한 것이 아닌가! 하여 구현해 보려고 하였습니다. `FruitStore`를 singleton으로 사용하고자 한 이유는 아래와 같습니다. - 과일 재고 저장소이기 때문에 과일쥬스를 만들 때 과일을 가져다 써야 함 - 과일의 재고를 추가하거나 감소시키는 기능이 있어야 함 - 위의 기능을 수행할 때 `FruitStore`가 아닌 **외부에서 접근할 가능성**이 있고, 한 곳에서 재고가 관리되어야 하므로, `singleton`으로 구현할 필요성 느낌 2. **쥬스를 주문하는 경우 어떠한 형식으로 전달받을 것인가?** 쥬스 버튼을 눌렀을 때 어떤 쥬스인지, 쥬스를 만들 때 어떤 재료가 얼마나 들어가는지에 대해 고민해 보았습니다. `String` 타입으로 메세징을 한다고 가정한 후 아래와 같은 규칙을 정립하고 구현해 보았습니다. - 메세지의 규칙을 정하여 쥬스별 레시피 String 제작 - 과일 재료 요약어와 필요한 재료 수를 붙임 - 2가지 이상의 재료가 필요한 경우 `+`로 연결 - `예) 딸기쥬스 - Sb16, 딸바쥬스 - Sb10+Bn1` - 쥬스 버튼을 누르면 전달될 메세지를 `enum`으로 정의 - 버튼을 누르면 해당 쥬스에 맞는 메세지가 `makeJuice`로 전달 (미구현!) (Step 1 요구사항에는 명시되어있지 않아서 미구현 상태입니다!) **JuiceMaker.swift** ```swift= enum RecipeMessage: String { case strawberryJuice = "Sb16" case bananaJuice = "Bn2" case kiwiJuice = "Kw3" case pineappleJuice = "Pa2" case strawBananaJuice = "Sb10+Bn1" case mangoJuice = "Mg3" case mangoKiwiJuice = "Mg2+Kw1" ``` 3. **`JuiceMaker` 에게 쥬스제작에 필요한 재료들과 그 양을 어떻게 전달할 것인가?** - 각 쥬스종류를 `Enum`으로 정의한후 필요한 과일 이름과 갯수를 특정 코드와 숫자로하여 원시값으로 String으로 정의하고 전달할 수 있게 함. - 이후 버튼이 눌릴때마다 원시값(`RecipeMessage`의 Rawvalue)는 해당 `Enum`의 타입메서드인 `translate`에 의해서 `String`에서 구조체인 `OrderMessage`로 변환되어 반환된다. **JuiceMaker.swift** ```swift= enum RecipeMessage: String { // ... static func translate(recipeMessage :String) -> [OrderMessage] { var convertedString: [OrderMessage] = [] let splitedString = recipeMessage.split(separator: "+") splitedString.forEach{ let fruitCode = String($0.prefix(2)) let amountStartIndex = $0.index($0.startIndex, offsetBy: 2) let amountCode = Int($0[amountStartIndex...]) ?? 0 convertedString.append(OrderMessage(fruitName: fruitCode, amount: amountCode)) } return convertedString } } ``` 4. **`JuiceMaker`는 왜 struct로 구현되어 있는가?** 아래의 구조체 사용 case 중 **다른 타입으로부터 상속받거나 자신을 상속할 필요가 없을 때**에 해당한다고 생각하여 struct로 구현되어 있는 것이라고 생각하였습니다. - 애플은 [가이드라인](https://developer.apple.com/documentation/swift/choosing-between-structures-and-classes)에서 다음 조건 중 하나 이상에 해당한다면 구조체를 사용할 것을 권장함 - 연관된 간단한 값의 집합을 캡슐화하는 것만이 목적일 때 - 캡슐화한 값을 참조하는 것보다 복사하는 것이 합당할 때 - 구조체에 저장된 프로퍼티가 값 타입이며 참조하는 것보다 복사하는 것이 합당할 때 - 다른 타입으로부터 상속받거나 자신을 상속할 필요가 없을 때 --- ## 🙋 질문 1. 저희가 구현한 레씨피(`RecipeMessage`의 rawValue)를 전달하는 방식이 바람직한지 의문이 듭니다. - **의도**: 각 switch로 메뉴별로 분기를 나눠서 할수도 있었지만 추후에 과일들이 들어가는 양과 조합이 달라질 수 있다는걸 고려해서 조금더 유연한 설계를 목적으로 했습니다. - 조금더 효율적이고 좋은 방법이 있으시다면 힌트를 주시면 감사하겠습니다! 2. 주말동안 개인적으로 protocol, 의존성 주입에 대해 학습 후 이번 프로젝트에 적용해 볼 예정입니다! 혹시 웨더가 생각하기에 protocol을 사용해 봤으면 좋겠다! 싶은 부분이 있다면 힌트 좀 주실수 있을까요? 왜 사용해야 하는가? 에 대한 부분은 저희가 학습하면서 찾아보고, 다음 PR에서 질문드리도록 하겠습니다!

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully