객체 공장

R에서 S3와 R6로 배우는 Object-Oriented Programming

Richie Cotton

Data Evangelist at DataCamp

 

ch3_1-the-object-factory.003.png

R에서 S3와 R6로 배우는 Object-Oriented Programming

 

 

클래스 생성기는 객체의 템플릿입니다

R에서 S3와 R6로 배우는 Object-Oriented Programming

 

 

클래스 생성기는 객체의 템플릿, 즉 공장입니다

R에서 S3와 R6로 배우는 Object-Oriented Programming

ch3_1-the-object-factory.007.png

R에서 S3와 R6로 배우는 Object-Oriented Programming

 

ch3_1-the-object-factory.009.png

R에서 S3와 R6로 배우는 Object-Oriented Programming

 

ch3_1-the-object-factory.010.png

R에서 S3와 R6로 배우는 Object-Oriented Programming

 

library(R6)
thing_factory <- R6Class(
  "Thing",

private = list( a_field = "a value", another_field = 123 )
)
R에서 S3와 R6로 배우는 Object-Oriented Programming

곧 나옵니다...

 

 

     public

     active

R에서 S3와 R6로 배우는 Object-Oriented Programming

 

a_thing <- thing_factory$new()
another_thing <- thing_factory$new() 
yet_another_thing <- thing_factory$new()
R에서 S3와 R6로 배우는 Object-Oriented Programming

요약

  • R6 패키지를 불러오십시오.
  • R6Class()클래스 생성기를 정의합니다.
  • 클래스명은 UpperCamelCase로 합니다.
  • 데이터 필드private 리스트에 저장합니다.
  • 공장의 new() 메서드로 객체를 생성합니다.
R에서 S3와 R6로 배우는 Object-Oriented Programming

연습해 봅시다!

R에서 S3와 R6로 배우는 Object-Oriented Programming

Preparing Video For Download...