본문 바로가기
Python/Web Scraping

[Python] #3.2 Intro to Object Oriented Programming (#코딩공부)

by 함께 공부해요 2020. 2. 28.

https://youtu.be/OiaXhERY3Kw


<복습>

https://wook-2124.tistory.com/46

 

[Python] #3.0 Django is AWESOME / #3.1 *args **kwargs (#코딩공부)

https://youtu.be/ol3eYQlCaUM <복습> https://wook-2124.tistory.com/45 [Python] #2.15 Saving to CSV(Comma-separated values) / #2.16 OMG THIS IS AWESOME (#코딩공부) https://youtu.be/1tGVS0LO2Do <복습>..

wook-2124.tistory.com


<준비물>

https://repl.it/

 

Online IDE, Editor, and Compiler - Fast, Powerful, Free

Repl.it is a simple yet powerful online IDE, Editor, Compiler, Interpreter, and REPL. Code, compile, run, and host in 50+ programming languages: Clojure, Haskell, Kotlin (beta), QBasic, Forth, LOLCODE, BrainF, Emoticon, Bloop, Unlambda, JavaScript, CoffeeS

repl.it


<코드기록>

 

# class는 Blueprint(설계도)역할
# 그 안에 property인 wheels, doors, windows, seats가 있음
class Car():
  wheels = 4
  doors = 4
  windows = 4
  seats = 4


# instance는 그 설계도로 만든 실제 결과물을 뜻함
# 즉 wheels, doors, windows, seats는 Car의 기본 요소니까 설계도에 있는대로 따라가고
# color는 차마다 다를 수 있으니까 따로 지정해준 것!
# Car() << 이것을 instantiation이라고 함 - 설계도를 가져와서 instance를 만드는 행위
porche = Car()
porche.color = "Red"

ferrari = Car()
ferrari.color = "Yellow"

mini = Car()
mini.color = "White"

1. Object Oriented Programming(OOP) - 객체 지향 프로그래밍

https://ko.wikipedia.org/wiki/%EA%B0%9D%EC%B2%B4_%EC%A7%80%ED%96%A5_%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D

 

객체 지향 프로그래밍 - 위키백과, 우리 모두의 백과사전

위키백과, 우리 모두의 백과사전. 객체 지향 프로그래밍(영어: Object-Oriented Programming, OOP)은 컴퓨터 프로그래밍의 패러다임 중 하나이다. 객체 지향 프로그래밍은 컴퓨터 프로그램을 명령어의 목록으로 보는 시각에서 벗어나 여러 개의 독립된 단위, 즉 "객체"들의 모임으로 파악하고자 하는 것이다. 각각의 객체는 메시지를 주고받고, 데이터를 처리할 수 있다. 객체 지향 프로그래밍은 프로그램을 유연하고 변경이 용이하게 만들기 때문에

ko.wikipedia.org

객체 지향 프로그래밍(Object-Oriented Programming, OOP)은 여러 개의 독립된 단위, 즉 "객체"들의 모임이다.

 

OOP(Object-Oriented Programming)기본 구성 요소로는 "클래스, 객채, 인스턴스, 메서드, 메시지"가 있다.

 

그리고 특징으로는 "추상화, 상속, 다중 상속, 다형성, 동적바인딩"이 있다.

 

장점으로는 높은 응집력과 낮은 결합력이 있고, 객체 지향 언어로는 "C, C++, C#, 파스칼, 델파이, Python, Perl, Ruby, 액션스크립트 등"이 있다.


2. Class? Instance?

먼저 class는 bluepirnt(설계도)와 같은 것이다.

 

그리고 instance는 이 설계도(class)를 가지고 만든 여러 복제품을 뜻한다. 즉 설계도로 만든 살아있는 결과물, 산출물이라고 생각하면 된다.


3. 예제로 class, instance 알아보기

class Car() 은 설계도(class), porche는 설계도로 만든 instance를 뜻한다.

 

porche. 을 입력하면 뒤에 만들어둔 설계도(class)의 세부내용 property(method)인 wheels, doors, windows, seats가 뜨면서 어떤 것을 만들지(어떤 method를 쓸지) 뜬다.

 

porche.color = "Red"처럼 color(method)를 Car(class)에 추가할 수 있다.

 

정리하자면 Car(class)에 property(method)인 wheels, doors, windows, seats가 있고, Car()를 instantiation(인스턴스화)이라고 한다. 즉 설계도(class)를 가져와서 산출물(instance)를 만드는 행위를 뜻한다. ()는 Button!!


※ 신종 코로나 바이러스 조심하세요!!!!

댓글