본문 바로가기
SAP/Complete ABAP

8.4 Inheritance

by Radler 2023. 2. 22.

Superclass는 Subclass로 어떤 것들이 있는 지 모르지만, Subclass는 그들의 Superclass를 알고 있다. 
즉, Super는 Sub의 메서드(컴포넌트)가 어떤 것들이 있는 지 볼 수 없는 데 반해, Sub은 Super의 메서드(컴포넌트)를 볼 수 있을 뿐더러, 


Subclass내 definition 부분 내 Redefinition 구문을 통해 Superclass의 메서드를 재정의(수정)할 수 있다. 

(그렇다고 Superclass내 원본 메서드를 수정하는 건 아님.) 
오직 Superclass의 Instance Public, Instance Protected 컴포넌트들만 redefine될 수 있으며, static 컴포넌트는 redefine 불가능하다. 왜냐하면, Static은 상속이 불가능하기때문이다. 
Super 참조는 오직 Redefined 메서드에서만 사용가능하다. 
Super에 Instance constructor가 있다면, sub에서 무조건 Super class내 Instance constructor의 importing 파라미터를 가져와서 Subclass내의 interface 내(여기서는 instance constructor 내)에서 다뤄야한다.

추상클래스
클래스의 템플릿을 만들고 싶은데, 그렇다고 Super의 기능을 본딴 템플릿을 만들고 싶지 않을 때, 추상클래스를 이용한다. 
정의부는 정의부만 선언하고, 실현부는 선언할 필요가 없다. 
왜냐하면, 추상클래스 자체가 템플릿으로서 구체적인 실현부 로직은 Redifinition을 통해 Subclass들에서 짜여질 목적이기때문이다. 

Final 
Final 선언하여 정의부/실현부 작성할 시, 더 이상 Redefining/Inheriting이 불가능하다. 

Composition 
Is-a 관계 : 예, Car-Vehicle, Subclass 생성하는 것으로 구현.
Has-a 관계(Composition 관계) : 예, Car-Wheels, Car class에 Wheels 속성 넣는 것으로 구현. 

Refactoring
상단 메뉴바의 Utilities-Refactoring-Refactoring Assistant 클릭하여, Subclass들의 components, hierarchy들을 정리할 수 있다. 

'SAP > Complete ABAP' 카테고리의 다른 글

8.6 EXTENSIBLE MARKUP LANGUAGE(XML)  (0) 2023.02.22
8.5 Polymorphism  (0) 2023.02.22
8.3 Encapsulation  (0) 2023.02.05
8.2 Principles of OOP  (0) 2023.02.05
8.1 Procedural Programming versus Object-Oriented Programming  (0) 2023.02.05