12.1 Welcome to object-oriented programming

주홍영·2022년 3월 15일
0

Learncpp.com

목록 보기
125/199

https://www.learncpp.com/cpp-tutorial/welcome-to-object-oriented-programming/

object, "a piece of memory that can be used to store values”
그리고 이러한 object가 name과 함께 있을때 이를 variable이라고 한다

전통적인 프로그램은 데이터와 function이 분리된 entity(독립체) 였다
따라서 전통적인 프로그래밍은 현실의 직관적인 표현과 좀 동떨어져 있었다

그렇다면 object oriented programming은 무엇인가?
너의 주위를 둘러봐라. 모든 것이 object이다
object는 두가지 주요한 component(부품)을 가지고 있다
1) A list of relevant properties (e.g. weight, color, size, solidity, shape, etc…),
2) Some number of behaviors that they can exhibit (e.g. being opened, making something else hot, etc…).

즉 특징과 동작이라는 부품 가지고 있다 property와 behavior

Object-oriented programming (OOP) provides us with the ability to create objects that tie together both properties and behaviors into a self-contained, reusable package. This leads to code that looks more like this:
oop는 이러한 property와 behavior가 결합된 재사용 가능한 패키지를 제공한다

driveTo(you, work);
you.driveTo(work);

위에가 기존에 object와 function이 분리된 코딩 스타일이라면
아래는 you라는 객체의 동작인 driveTo와 work라는 객체를 목표물로 받는다는 것을
직관적으로 이해할 수 있는 스타일이다

이는 가독성만 높이는 것이 아닌 무엇이 정확히 주체이고 (you) 어떠한 behavior가 invoked (호출된) 지에 대한 명확하게 보인다
따라서 우리는 function에 대해서 집중하는 것이 아닌
잘 define된 object와 그에 따라서 define된 behavior에 집중할 수 있다
이것이 왜 object oriented(지향적인) 이라고 불리는 이유일 것이다

이는 프로그램이 더욱 modular한 방법으로 쓰일 수 있도록 도와주고
코드를 쓰고 이해하는데 도움을 주며 높은 코드 재사용성을 지원한다

또한 OOP는 몇가지 다른 유용한 개념들도 부각시킨다
inheritance, encapsulation, abstraction, and polymorphism

전통적인 프로그램에서 object란 데이터가 저장된 메모리 조각과 같은 느낌이지만
oop에서 object는 앞선 의미와 더불어 property와 behavior가 결합된 개념이다

profile
청룡동거주민

0개의 댓글