티스토리 뷰
@implementation Circle
- (void) setFillColor: (ShapeColor) c
{
if (c == kRedColor){
c = kGreenColor;
}
[super setFillColor: c];
} // setFillColor
// and the rest of the Circle @implementation
// is unchanged
@end // Circle
------------------------------------------
빨간 원을 녹색 원으로 바꾸는 소스이다. setFillColor: 가 Shape에 정의되어 있는 경우,
super를 사용해서 수퍼클래스(Shape)에게 fillColor의 인스턴스 변수에 변경된 색을 저장할 수 있도록 할 수 있다.
(super에 메시지를 보내면 Objective-C에게 그 클래스의 수퍼클래스에 메시지를 보내라고 요청하는 것이 된다.)
'나름 프로그래밍? > Objective-C' 카테고리의 다른 글
접근자 메소드 (0) | 2010.02.04 |
---|---|
컴포지션의 의미 (0) | 2010.02.04 |
상속의 경우 메소드 디스패칭 (2) | 2010.01.28 |
- (void)draw 선언 및 구현 (0) | 2010.01.28 |
@interface Circle : Shape (0) | 2010.01.28 |