Skip to content

장예슬) 필수과제 4, 5번 문제입니다#8

Open
yy-ss99 wants to merge 18 commits intomainfrom
YS
Open

장예슬) 필수과제 4, 5번 문제입니다#8
yy-ss99 wants to merge 18 commits intomainfrom
YS

Conversation

@yy-ss99
Copy link
Copy Markdown
Collaborator

@yy-ss99 yy-ss99 commented Jan 9, 2026

No description provided.

@yy-ss99 yy-ss99 changed the title 장예슬) 필수과제 3, 4번 문제입니다 장예슬) 필수과제 4, 5번 문제입니다 Jan 9, 2026
Comment on lines +140 to +154
for i in introducibleArray {
switch i {
case is Cat:
let cat = i as! Cat
print(cat.meow())
case is Dog:
let dog = i as! Dog
print(dog.bark())
case is Robot:
let robot = i as! Robot
print(robot.charge())
default:
print("해당없음")
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 if문으로 처리했었는데 switch문이 훨씬 직관적으로 이해하기 쉬운 것 같네요! 참고하고 갑니당ㅎㅎ☺️

Comment on lines +10 to +13
protocol Introducible {
var name: String { get set }
func introduce() -> String
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name 프로퍼티를 { get set }으로 선언하신 이유가 있으실지 궁금합니다..!

프로토콜을 채택한 객체 내에서 name을 따로 연산 프로퍼티로 사용하거나 하시진 않은 것 같아 여쭈어봅니당..ㅎㅎ

프로퍼티 선언 시 { get set }으로 선언을 하면 프로토콜을 채택한 객체에서 해당 프로퍼티는 var로만 선언 가능하여 구현의 자유도가 떨어진다고 하더라고요.(let으로 선언 불가능) 좀더 자유로운 구현을 위해 제한 사항을 덜어주는 게 어떨까 말씀드려봅니다..!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 예슬님도 프로토콜 채택 객체들 class로 선언해주신 걸로 확인했습니당...!! 저도 예슬님 코드처럼 수정했어요...😂😂
클래스에 채택하면 프로토콜 타입으로 인스턴스 생성 시 name 값 변경이 불가능하네요.. 하핳 위의 제 의견은 무시해주십셔..👉👈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants