본문 바로가기
SW 공부/Design Patterns

OBJECT-ORIENTED PARADIGM

by 꼬냉상 2022. 8. 23.

Object-Oriented Paradigm

객체 지향 패러다임 

Class = ADT + Inheritance + Polymorphis

Abstract Data Type (ADT) 

- Encapsulation of data and related operations into a single syntactic unit

- 하나의 문법적 요소 안에 data나 관련 작업을 캡슐화 

 

Inheritance

- 상속

- When class Y inherits from class X,  We can use the instance of Y wherever the instance of type X is expected

 

- 클래스 Y가 클래스 X에서 상속될 때, 우리는 type X의 인스턴스가 예상되는 모든 곳에서 Y의 인스턴스를 사용할 수 있다.

 

Polymorphism

- 다형성

- operation (typically virtual) may be performed in different ways in different classes.

- 같은 명령에 서로 다른 클래스에서 서로 다른 방식으로 수행될 수 있다. 

 

=> 이 3가지 요소를 합치면, 캡슐화한 요소를 가지고 재사용성이 좋고 유연성이 향상된 Class를 만드는 것

 

Method Oveloading

- Method Overloading : Compile time polymorphism (Static polymorphism)

Method Overriding

- Method Overriding : Runtime polymorphism (Dynamic polymorphism)

 

What is an Interface?

- All methods defined in an interface are abstract, Interfaces cannot contain any implementation.

- 인터페이스에 정의된 모든 방법은 추상적이며, 인터페이스는 구현을 포함할 수 없다.

- 인터페이스는 인스턴스 변수를 포함할 수 없으나,  public static final 변수는 포함 가능

 

Class Relationships

Dependency Association Aggregation Composition Inheritance
work briefly  some prolonged amount of time owns, but shares a reference contains objects when one class is a type of another class
한 클래스의 객체가 다른 클래스의 객체와 잠시 작동하는 경우 한 클래스의 객체가 다른 클래스의 객체와 장시간 작업하는 경우 한 클래스가 다른 클래스의 개체를 소유하지만 참조를 공유하는 경우 한 클래스에 다른 클래스의 개체가 포함된 경우 한 클래스가 다른 class의 한 종류일 때
<---- Weaker relationship   Stronger relationship ---->

Soure class -> Targer class 방향에 따라 Chnage propagtion을 파악해 보면

- Target이 변경되면 Source가 영향을 받을 수 있으나,

- Target 대상이 Source를 모르기 때문에 Source의 변경은 전파되지 않는다.

=> Design 단계에서 체크해 둬야 함!

 

Quiz) 다음 중 에러 없이 컴파일되는 코드는?

interface IType { }
abstract class Type1 implements IType { }
class Type2 implements IType { }
class Type3 extends Type1 { }
class Type4 extends Type2 { }

(a) Type1 a1 = new Type1();  → abstract는 new가 안됨

(b) IType a2 = new Type2();

(c) Type1 a3 = new Type2();  → (시블링) 형제관계

(d) IType a4 = new Type4();

(e) Type2 a5 = new IType(); → interface는 new가 안됨

(f) Type1 a6 = new Type3();

(g) Type3 a7 = new Type4(); → (시블링) 형제관계

 

 

 

 

Quiz) O/X 로 답하시오

- (X) 메쏘드 오버라이딩을 하면 호출된 메쏘드가 링킹(linking-time)에 결정된다.

Method Overriding : Runtime polymorphism (Dynamic polymorphism)

 Method Overloading : Compile time polymorphism (Static polymorphism)

 

Quiz) 다음 그림에서 AccountAPI 인터페이스의 getInvoice 메쏘드에 파라미터가 추가될 경우, 해당 변경에 영향을 받을 수 있는 모든 클래스와 인터페이스의 이름을 쓰고, 이유를 설명하시오. 

<Class relationship and Change Propagation>

If Target changes, then Source may be affected.  (Target이 변경되면 Source는 영향을 받음)

Target is ignorant of Source, hence the change of Source is not propagated. (Target은 source를 모르기 때문에, Source 변경은 전파되지 않습니다. )

 

- Student Enrollment : AccountAPI interface를 realization한 Class로 getInvoice() 메소드의 직접적인 구현부이기 때문에 영향이 갑니다.

- Course : 영향을 받은 Student Enrollment를 0~다수를 가지고 사용할 수 있기 때문에 영향이 갑니다.

- Account Application (?) : 해당 AccountAPI interface를 파라미터와 함께 호출하는 aaplication 이므로 영향이 갑니다.

 

본 글은 개인의 S/W 구조설계 역량 강화를 위한 학습 목적으로 정리된 내용입니다.
일부 타/개인 단체에 저작권이 있는 자료를 포함하고 있으므로, 절대 영리 목적으로 사용하실 수 없습니다.
반응형

댓글