Structure, Class 비교해보기

Groot·2022년 6월 7일
0

TIL

목록 보기
10/148
post-thumbnail

TIL

🌱 난 오늘 무엇을 공부했을까?

📌 Structure, Class 비교해보기

📍 Structure, Class 공통점

  • Define properties to store values
  • Define methods to provide functionality
  • Define subscripts to provide access to their values using subscript syntax
  • Define initializers to set up their initial state
  • Be extended to expand their functionality beyond a default implementation
  • Conform to protocols to provide standard functionality of a certain kind

📍 구조체에 없는 Class 의 기능

  • Inheritance enables one class to inherit the characteristics of another.
  • Type casting enables you to check and interpret the type of a class instance at runtime.
  • Deinitializers enable an instance of a class to free up any resources it has assigned.
  • Reference counting allows more than one reference to a class instance

📍 FruitStore 타입은 왜 클래스로 구현하라고 요구했을까?

  • 값의 원본 값을 참조해야하기 때문에 클래스로 구현
  • FruitStore의 상속의 확장성을 고려해야 할 수 있기 때문에

📍 JuiceMaker 타입은 왜 구조체로 구현하라고 요구했을까?

  • 여러군데에서 복사해서 사용 할 수 있어야 해서.
  • class를 사용할 이유가 없기 때문에
profile
I Am Groot

0개의 댓글