Skip to content

Instantly share code, notes, and snippets.

@nattybear
Last active January 23, 2021 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nattybear/2b2cd814aea7ecacb5327f539d33cd5e to your computer and use it in GitHub Desktop.
Save nattybear/2b2cd814aea7ecacb5327f539d33cd5e to your computer and use it in GitHub Desktop.

이 글은 Canol Gokel님이 만든 Computer Programming using GNU Smalltalk를 읽고 정리한 것이다.

Creating Objects from Classes

생성한 클래스의 객체를 만들 때는 아래와 같이 한다.

ourObjectName := SubclassName new

SubclassName 클래스에 new 메세지를 보내서 객체를 만들었다.

그런데 우리가 직접 new 메소드를 만든 적이 없는데 어떻게 된 걸까?

상속 덕분에 가능한 것이다.

모든 클래스와 객체는 new 메소드를 기본으로 가지고 있다.

객체 변수로 클래스 메소드를 사용하려고 하면 에러가 난다.

ourObjectName aClassMethod

클래스 메소드를 사용하려면 클래스 이름에 해야 한다.

SubclassName aClassMethod

또는 아래처럼 class 메소드를 이용하면 가능하다.

ourObjectName class aClassMethod

Computer Programming with GNU Smalltalk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment