일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- SWIFT
- ChatGPT
- sql
- 카카오인턴십
- 코테
- 부주상골
- 카카오코테
- 롯데정보통신
- c++
- 카카오인턴
- BFS
- 부주상골증후군
- DFS
- 리눅스
- 부주상골수술
- istringstream
- dp
- 독일어독학
- 코딩테스트
- 독일어
- 독학
- 세브란스
- 부주상골수술후기
- 프로그래머스
- IOS
- 백준
- 분할정복
- 스택
- SQLD
- 구현
Archives
- Today
- Total
슈뢰딩거의 고등어
모델 설계시 Structure, Class 중 어느 것을 사용해야할까 본문
개인 프로젝트 도중, User 와 Post 에 사용할 모델을 만들어야 했다.
일단 Post 는 별 생각 없이 구조체로 만들었는데, 클래스로 만들어도 되지않나? 라는 생각이 문득 들어서
챗지피티에게 물어봤다.
The choice between using a structure (struct) or a class (class) depends on the specific requirements and characteristics of your application.
Here are some factors to consider:
- Mutability: Structures are value types, meaning they are typically immutable. When you create a new instance of a structure or assign it to a new variable, a copy is made. This can be beneficial in scenarios where you want to ensure immutability and avoid unexpected side effects. On the other hand, classes are reference types, and multiple references can point to the same instance. If you need mutability and shared references to the same instance, classes may be a better choice.
- Inheritance: Classes support inheritance, allowing you to create subclasses that inherit properties and behaviors from a base class. If you need to model an inheritance hierarchy or create specialized subclasses, classes are the appropriate choice. Structures, on the other hand, do not support inheritance.
- Performance: Structures are typically more lightweight and have better performance characteristics compared to classes. Since structures are copied when assigned or passed as function arguments, they can be more efficient in terms of memory usage. However, this performance advantage may vary depending on the specific use case and the size of the structure.
흠 그냥 구조체로 다 만들어도 될 것 같다.
따로 뭐 Inherit 가 필요한 성격이 아니기도 하고, 더 구조체가 가볍다고 하니...
각자의 프로젝트 성향에 맞게 하면 될듯한데, 단순 user 는 뭐 구조체정도로 뚝딱 만드는게 나을듯
'14일만에 IOS 앱 끝내기 챌린지' 카테고리의 다른 글
IOS 사용자 위치정보 얻기 (0) | 2023.04.08 |
---|---|
(13일차, 14일차) 14일 만에 IOS 앱 끝내기 챌린지 : 슬롯머신 만들기 (0) | 2023.03.04 |
(11일차, 12일차) 14일 만에 IOS 앱 끝내기 챌린지 : State Properties, If 조건문 (0) | 2023.03.04 |
(10일차) 14일 만에 IOS 앱 끝내기 챌린지 : SwiftUI 버튼 (0) | 2023.03.04 |
(8일차, 9일차) 14일 만에 IOS 앱 끝내기 챌린지 - Swift 프로그래밍 : 구조체, 객체 (0) | 2023.03.01 |
Comments