Hamo
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me 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
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    아래 여러 상황에서 각각의 상황에 맞는 방법을 클래스의 상속과 프로토콜 기본 구현 중 골라서 직접 코드로 구현해보세요. - 상황 1 : 야곰 아카데미 구성원 각각의 역할을 표현하고 싶을 때 (ex : 캠퍼, 크루, 리더, 매니저, 서포터, 리뷰어 등) ```swift! class YagomAcademyMember { let membership: String = "나는 야곰아카데미 구성원" } class YagomAcademyLeader: YagomAcademyMember { } class YagomAcademyCrew: YagomAcademyMember { } class YagomAcademyManager: YagomAcademyMember { } class YagomAcademySupporter: YagomAcademyMember { } class YagomAcademyReviewer: YagomAcademyMember { } class YagomAcademyCamper: YagomAcademyMember { } let hamo1: YagomAcademyCamper = YagomAcademyCamper() print(hamo.membership) // 내가 야곰아카데미의 캠퍼이자 서포터라면? //let hamo: YagomAcademyCamper, YagomAcademySupporter // 불가능 // 어떻게 해야 되냐 // class YagomAcademyCamper였다가YagomAcademySupporter // 를 만들라 했는데 다중 상속이 안되서 불가능 protocol CanYagomAcademyMember { } extension CanYagomAcademyMember { var membership: String { return "나는 야곰아카데미 구성원" } } protocol CanYagomAcademyLeader: CanYagomAcademyMember { } protocol CanYagomAcademyCrew: CanYagomAcademyMember { } protocol CanYagomAcademyManager: CanYagomAcademyMember { } protocol CanYagomAcademySupporter: CanYagomAcademyMember { } protocol CanYagomAcademyReviewer: CanYagomAcademyMember { } protocol CanYagomAcademyCamper: CanYagomAcademyMember { } struct YagomAcademyCamper이면서YagomAcademySupporter: CanYagomAcademyCamper, CanYagomAcademySupporter { } // 내가 야곰아카데미의 캠퍼이자 서포터라면?? let hamo: YagomAcademyCamper이면서YagomAcademySupporter = YagomAcademyCamper이면서YagomAcademySupporter() print(hamo.membership) // 클래스로 했을 때 한계점은 유연하지 못함 // 하나의 추상화를 선택하도록 강요됌 // 프로토콜 기본 구현의 한계점 // stored property를 못쓴다. // 클래스의 상속과 프로토콜 기본 구현이 모두 가능한 상황이라면, 뭘 선택할 지 고민해봐야 하는 지점이 뭘까? // ``` - 상황 2 : 각종 도형(삼각형, 사각형, 정사각형, 직사각형, 평행사변형 등등)을 타입으로 표현하고 싶을 때 ```swift // 프로토콜을 사용한다면? protocol 넓이계산able { var type: 도형의종류 { get } var width: Double { get } var height: Double { get } func 넓이를계산해보겠다() -> Double } extension 넓이계산able { func 넓이를계산해보겠다() -> Double { switch type { case .삼각형: return width * height * 0.5 default: return width * height } } } enum 도형의종류 { case 삼각형, 사각형, 직사각형 } struct three각형: 넓이계산able { var type: 도형의종류 = .삼각형 var width: Double = 3 var height: Double = 3 } let myThree각형 = three각형() myThree각형.넓이를계산해보겠다() //4.5 ``` - 상황 4 : 포켓몬(피카츄, 라이츄, 파이리, 꼬부기, 또가스, 또도가스, 잉어킹, 갸라도스 등등)을 표현하고 싶을 때 ```swfit enum Attribute: String { case fire = "불속성" case water = "물속성" case electric = "전기속성" case gas = "가스속성" } protocol Pocketmon { var name: String { get } var type: Attribute { get } func attack() func defense() } extension Pocketmon { func attack() { print("\(self.name)(이)가 \(self.type.rawValue) 공격합니다.") } func defense() { print("\(self.name)(이)가 방어합니다.") } } struct Pikachu: Pocketmon { let name: String let type: Attribute init() { self.name = "피카츄" self.type = .electric } } ``` - 4개 중 3개 선택하여 진행 - 각각의 상황에서 해당 방식을 택한 이유는 무엇인가요 - 상황 1 - 두 가지 역할을 동시에 가져야하는 경우에는 상속보다 프로토콜이 더 낫다고 생각되어 선택하였다. - 상황 4 - 포켓몬이 갖는 공통된 이름, 속성, 공격메서드, 방어메서드를 프로토콜로 두고 공격, 방어 메서드를 기본 정의하여 사용하기 위해 프로토콜을 사용했다. 상속을 통해 이루어진다면, 공격과 방어 메서드에서 사용되는 name과 type의 값이 상위 클래스에서도 선언되어야 하는데 불필요한 선언을 하는 것 같아서 상속대신 프로토콜을 채택했다.q - 각 방식의 한계점에는 무엇무엇이 있을까요? - 클래스로 했을 때 한계점은 유연하지 못함 - 하나의 추상화를 선택하도록 강요됌 - 같은 기능을 사용할 때 override가 반복됨 - 불필요한 코드까지 모두 상속받음 - 프로토콜로 했을 때 한계점 - 재정의 불가 - stored property 불가 - 클래스의 상속과 프로토콜 기본구현이 모두 가능한 상황이라고 가정한다면, 둘 중 하나의 방법으로 선택에 있어 고민해봐야 하는 지점은 무엇이 있을까요? - 성능 - 유연함 - 유지보수하기 편한지 # TCP/IP 정리 - TCP/IP가 나타난 이유는 컴퓨터간 통신을 위해서이다. - 인터넷으로 연결된 수 많은 컴퓨터와 통신을 위해서 TCP/IP를 선택한 이유는 개방성에 있다. - 즉, 하드웨어, 운영체제, 접속 매체에 관계없이 동작할 수 있다는 점 때문에, 인터넷 통신을 위한 핵심으로 선택되었다. TCP/IP는 2개의 프로토콜로 이루어져 있음!! <aside> 💡 프로토콜이란 컴퓨터와 네트워크 기기가 상호간에 통신하기 위해서는 서로 같은 방법으로 통신하지 않으면 안된다. 어떻게 상대를 찾고, 소통하고 종료하는지와 같은 규칙이 필요하다. 서로 다른 하드웨어와 운영체제 등이 서로 통신을 하기 위해 모든 요소에 규칙이 필요한데 이런 규칙을 프로토콜이라고 부른다. </aside> ### IP - node(단말기)와 node (컴퓨터와 컴퓨터라고 쉽게 이해해보자) 간의 데이터 패킷을 전송하기 위해서는 각 node의 주소를 필요로 한다. 전 세계 수억대의 node에 특별한 주소를 부여했는데 이 주소를 IP주소라고 한다. - IP는 Internet Protocol의 줄임말로, 인터넷에서 컴퓨터의 위치를 찾아서 데이터를 전송하기 위해 지켜야 할 규약입니다. - IP는 4개의 숫자로 구성되며 숫자의 크기에 따라 IPv4(32비트, 각 숫자는 1바이트), IPv6(128비트, 각 숫자는 4바이트)로 나뉜다. - 숫자로된 인터넷주소를 사람이 식별하는건, 쉽지 않기 때문에 IP주소를 인간이 식별하기 쉬운 Domain 네임으로 변환시켜주는 Domain Name 서비스를 사용한다. DNS??? - 아래에서 보겠지만 IP는 맨 아래 계층으로 올바른 목적지를 찾는 패킷 GPS 역할을 한다. ### TCP - 서버와 클라이언트간에 데이터를 신뢰성있게 전달하기 위해 만들어진 프로토콜이다. - 데이터는 네트워크 선로를 통해 전달되는 과정에서 손실되거나 순서가 바뀔 수 있는데 이때 TCP는 전달받은 패킷을 재조립하고, 패킷에 손상이 있거나 손실된 패킷이 있다면 재전송을 요청하는 패킷을 전송하여 재전송 받습니다. - 데이타를 전송하기 전에 데이타전송을 위한 연결을 만드는 연결지향 프로토콜이다. ※ 패킷 : 데이터를 일정한 크기로 자른 단위로 인터넷에서 정보를 전달하는 단위 ## LAN, WAN과 TCP/IP LAN은 Local Area Network의 줄임말로 지역 네트워크이며 WAN은 Wide Area Network의 줄임말로 광역 네트워크이다. 즉, LAN은 지역적으로 가까운 컴퓨터가 서로 연결된 상태, WAN은 멀리떨어진 컴퓨터가 연결된 상태를 말한다. WAN은 LAN과 LAN 사이를 구성하는 네트워크를 의미한다고함!! 아래 그림이 LAN과 WAN의 구성을 보여주는 그림이라고함 ![](https://i.imgur.com/AExrbBz.png) HOST와 HOST 그리고 HOST와 Router는 다양한 종류와 품질을 가지는 네트워크 연결 회선으로 연결될 수 있음(구리선, 광케이블, 인공위성 등등) 이때 데이터 순서가 뒤바뀔 수 있는 이유는, 패킷이 전달되는데 여러 임의의 경로를 사용하기 때문에 각 경로를 구성하는 회선의 품질이 다르게되면 먼저 보낸 패킷이라도 더 느리게 도착할 수 있다.(구리선으로 전달되는 친구가 광케이블로 전달되는 친구보다는 느리게 움직임) TCP/IP는 이러한 연결된 상태에서 서로 올바른 통신을 하도록 도와준다. 사실 TCP가 이러한 기능을 가지고 있음 1. 패킷이 빠졌을 경우, 재전송을 요청하는 기능 2. 패킷에 일련번호를 줌으로써, 순서가 뒤바뀌면 재조합하는 기능 # TCP/IP가 어떻게 이용되는가?? 이것을 이해하기 위해서는 OSI7에 대한 이해가 필요하다. OSI는 각종 시스템간의 연결을 위해 ISO에서 제안한 모델임 Open System Interconnection Reference Model의 줄임말로, 시스템에 상관없이 서로의 시스템이 연결될 수 있도록 만들어주는 모델이다. ![](https://i.imgur.com/7U6Eihw.jpg) 컴퓨터와 컴퓨터 사이의 데이터전송을 위해서는 7개의 계층을 직-간접적으로 거쳐서 전송이 되게된다!! 7개의 계층으로 나눈 이유는, 각 계층에 대한 캡슐화와 은닉화가 가능하기 때문이다. 계층별로 나눔으로써, 각 계층에서 필요한 부분만을 개발자들이 신경쓰게 되고 통신서비스 개발 시간을 줄일 수 있도록 도와준다. ### TCP/IP는 4계층 TCP/IP는 더 단순화 시켜서 4개의 계층으로 만들어서 사용한다. ![](https://i.imgur.com/veZN3nT.png) 1. Application Layer - 프로그램이 직접 인터랙트하는 레이어, 데이터를 처음으로 받는 곳 - 다른 계층의 서비스에 접근할 수 있게 하는 어플리케이션을 제공 - 어플리케이션들이 데이터를 교환하기 위해 사용하는 프로토콜을 정의 - HTTP, SMTP 등의 프로토콜을 가진다. 2. Transport Layer - 도착을 원하는 시스템까지 데이터를 전송하기 위한 일을 하는 계층이다. - 각각의 시스템을 연결하고, TCP 프로토콜을 이용하여 데이터를 전송한다. 3. Internet Layer - 네트워크상 최종 목적지까지 정확하게 연결되도록 연결성을 제공한다. - 데이터 경로를 배정하는 일(라우팅)을 담당한다. - 데이터를 정확히 라우팅하기 위해서 IP 프로토콜을 사용한다. 4. Network Access Layer - TCP/IP 패킷을 네트워크 매체로 전달하는 것과 네트워크 매체에서 TCP/IP 패킷을 받아들이는 과정을 담당 - 에러 검출 기능(Detecting errors), 패킷의 프레임화(Fraimg packets) - 네트워크 접근 방법, 프레임 포맷, 매체에 대해 독립적으로 동작하도록 설계. - 물리적인 주소로 MAC을 사용 - LAN, 패킷망, 등에 사용됨 ## TCP/IP 4계층에 의한 데이터 전송 ![](https://i.imgur.com/4ObJK1W.png) ![](https://i.imgur.com/i5Kwik1.png) 예를들어, 브라우저에 URL을 입력해서 웹페이지를 요청한다고 해보자. 사용자의 요청은 인터넷상에서 전달되기 용이한 패킷으로 만들기 위해서 TCP 패킷으로 만들어지게된다. 이것은 인터넷 상에서 원하는 주소로 이동할 수 있도록 하기 위해서 IP패킷으로 다시 만들어지고 이것이 이더넷 카드로 보내어져서 Internet으로 나가게된다. Internet 상에서는 원하는 주소로 TCP/IP 패킷을 보내기 위한 여러가지 장치들이 존재하는데(라우터, 토큰링 같은), 이들 장치를 통해서, 해당 URL의 이더넷카드로 TCP/IP 패킷이 전달되게 된다. 그럼 이더넷 카드는 TCP/IP 패킷을 바로 윗 계층(Internet Layer)으로 보내는데, 여기에서는 IP 패킷을 분석해서, 이 패킷이 어디에서 왔으며, 그 도착지가 어디인지를 판단하게 된다.(물론 이는 IP주소 기반으로 판단한다) 그리하여 목적지가 자신이면 이것을 다시 Transport Layer 로 보내고, TCP 프로토콜을 사용하여, 메시지가 누락된게 있으면 다시 요청하고, 순서를 재조합하는등 통신 메시지를 검사해서 이것을 다시 Application Layer 에게 보낸다. Application Layer 에서는 웹서버(IIS, Apache 같은)가 통신메시지를 HTTP 프로토콜에 준하여, 검사를 하여서 사용자가 요청한 웹페이지를 읽어들여서, Transport 계층으로 보내게 된다. 웹페이지를 브라우저까지 전송하는 과정은 위의 정반대의 과정을 순차적으로 거치게 된다. 최종적으로 웹브라우저는 웹페이지를 받아서(text) 역시 HTTP 프로토콜에 준하여, 렌더링 작업을 거친후 화면에 뿌려주게 된다. 위의 그림에서 보면 알겠지만 각각의 계층은 각각의 계층만을 상관하고 있음을 알수 있다. 즉 Application Layer 에 위치하는 브라우저와 webserver 는 HTTP 프로토콜에 의해서 자신의 계층끼리만 통신을 하고, Transport Layer 은 역시 TCP 프로토콜에 의해서 Transport Layer 끼리 통시을 함을 알수 있을것이다. 말그대로 계층적 구조를 가지며, 각 계층은 대응되는 상대편의 계층에 대해서만 상관한다. [네트워크 프로그래밍 : TCP/IP 개론](https://www.joinc.co.kr/w/Site/Network_Programing/Documents/IntroTCPIP) [[Network] TCP / IP란 무엇인가?](https://coding-factory.tistory.com/613) [[Network ②] OSI 기본 참조 모델 (OSI 모델 / OSI 7계층 / TCP/IP 모델 )](https://datamoney.tistory.com/267?category=907188)

    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