티스토리 뷰
Circle |
fillColor bounds |
setFillColor: setBounds: draw |
Rectangle |
fillColor bounds |
setFillColor: setBounds: draw |
이와 같이 중복되는 부분이 많으면 비효율 적이다.
중복되는 코드를 한곳에 합쳐서 정리 하는 방법 - 상속.
Shape 클래스를 상속받아 Circle 과 Rectangle 를 정의 하면 이와 같다.
Circle 클래스를 수퍼클래스( 부모클래스 )라 부른다.
Circle 과 Rectange 클래스를 서브클래스 ( 자식클래스 ).
Circle 과 Rectangle 은 Shape 로 부터 상속을 받았기 때문에 Shape의 인스턴스 변수 fillColor 와 bounds 를 받는다.
메소드 또한 상속.
'나름 프로그래밍? > Objective-C' 카테고리의 다른 글
- (void)draw 선언 및 구현 (0) | 2010.01.28 |
---|---|
@interface Circle : Shape (0) | 2010.01.28 |
self -> fillColor = fillColor; (0) | 2010.01.28 |
@implementation - 실제 객체가 동작하는 코드 (0) | 2010.01.28 |
메소드 선언 방법 (0) | 2010.01.28 |