블로그 이미지
Leeway is... the freedom that someone has to take the action they want to or to change their plans.
maetel

Notice

Recent Post

Recent Comment

Recent Trackback

Archive

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
  • total
  • today
  • yesterday

Category

'Class'에 해당되는 글 8건

  1. 2008.04.14 Class와 Object
  2. 2007.07.18 David Hirmes - blobs01
  3. 2007.07.13 splash_class_multi
  4. 2007.07.13 splash_class
  5. 2007.07.12 progress_class
  6. 2007.07.11 생성자와 소멸자
  7. 2007.07.11 classes in Python
  8. 2007.03.16 <HeadFirst Java> 클래스와 객체
2008. 4. 14. 15:47 @GSMC/정문열: Generative Art
Head First Java 개정판
68쪽

인스턴스 변수 - 객체에서 자신에 대해 아는 것 (상태)
메소드 - 객체에서 자신이 하는 것 (행동)

인스턴스 변수 - 객체의 상태 - 데이터

"인스턴스(instance)란 객체(object)를 부르는 다른 이름이라고 생각하세요."

정 교수님:
C에서의 new와 Java에서의 new는 다르다.
C에서의 new는 memory를 allocate하는 데 반해,
Java에서의 new는 class의 constructor를 선언하는 것이다.

75쪽
자바 애플리케이션에서는 여러 클래스 가운데 한 클래스에 main 메소드가 있어야 한다. 그리고 그 클래스를 통해서 프로그램을 시작하게 된다.

클래스는 해당 클래스 유형의 객체를 만드는 방법을 설명하는 역할을 한다.



http://java.sun.com/javase/6/docs/api/java/lang/reflect/Array.html

http://java.sun.com/javase/6/docs/api/java/lang/Integer.html
noah:
Java에는 두 가지 종류의 int가 있다. 하나는 C에서와 같은 primitive 유형이고 다른 하나는 java.lang.Number를 상속하는 클래스 유형의 int이다.


'@GSMC > 정문열: Generative Art' 카테고리의 다른 글

변수  (0) 2008.05.17
class 5/1  (0) 2008.05.01
[이선애] study 1  (0) 2008.03.28
class 3/27  (0) 2008.03.27
tree (data structure)  (0) 2008.03.24
posted by maetel
2007. 7. 18. 12:41 Code/NodeBox
The mission I chose:
사용자 삽입 이미지

David Hirmes - blobs01

from Flash Math Creativity


우선, blob 하나의 움직임을 코딩해 보자.
#hirmes_blobs01_0.0

size(400, 200)
speed(100)

def setup():
    global x
    global v
    global a
   
    global check
    global c

    x = 0
    v = 10
    a = -0.1*v
   
    check = 0
    c = 0

def draw():
    global x
    global v
    global a
   
    global check
    global c
     
    v += a
    x += v
   
    if x > WIDTH:
        x = 0
    if x < 0:
        x = WIDTH
   
    check += c
       
    if v < 0:
        v = 0
        a = 0
        c = 1
    if check == 40:
        v = 15
        a = -1
        check = 0
          
    oval(x, 50, 50, 50)
전에 배운 pattern에서 실마리를 얻어 새로운 pattern을 만들어 보았다.
내가 생각해도 good idea! 쿄쿄.


이것을 아래의 move 메쏘드에 적용하면 된다.  
원하는 결과를 위해서는 다른 색의 방울 두 개에 동시에 동일한 움직임을 주어야 했는데, 이를 위해 Blob 클래스에서 움직임을 주는 메쏘드(move)와 색을 넣어 그리는 메쏘드(ball)를 분리하는 것을 하나의 해결책으로 제시해 보았다.
# hirmes_blobs01_0.1

class Blob:
    def __init__(self):
        self.f = 0
        
        self.x0 = 20
        self.y0 = 100
        self.x1 = 100
        self.y1 = 120
        
        self.v = 10
        self.a = -0.1*self.v
        self.check = 0
        self.c = 0
        
    def move(self):
        self.v += self.a

        self.x0 += self.v
        self.x1 += self.v * 0.8

        ###borders     
        if self.x0 > WIDTH:
            self.x0 = 0
        if self.x1 > WIDTH:
            self.x1 = 0
        if self.x0 < 0:
            self.x0 = WIDTH
        if self.x1 < 0:
            self.x1 = WIDTH  
       
       ###pauses
        self.check += self.c
        
        if self.v < 0:
            self.v = 0
            self.a = 0
            self.c = 1

        if self.check == 40:
            self.v = 15
            self.a = -1
            self.check = 0
        
    def ball(self, d, r, g, b):                    
        fill(r, g, b)
        ovalc(self.x0, self.y0, d, d)
        ovalc(self.x1, self.y1, d, d)
        
       
size(400, 300)
speed(30)


def setup():
    global bb
    
    bb = Blob()

    
def draw():
    global bb
    
    bb.move()
    bb.ball(80, 1, 0, 0)
    bb.ball(70, 1, 1, 1)

def ovalc(cx, cy, w, h):
    x = cx-w/2
    y = cy-h/2
    oval(x, y, w, h)  


이제 방울 수를 늘려 보자.
# hirmes_blobs01_1.0

class Blob:
    def __init__(self):
        ###initial position
        self.x0 = random(-WIDTH,WIDTH)
        self.x1 = random(-WIDTH,WIDTH)
        self.x2 = random(-WIDTH,WIDTH)
        self.x3 = random(-WIDTH,WIDTH)
        self.x4 = random(-WIDTH,WIDTH)
        self.x5 = random(-WIDTH,WIDTH)
        self.x6 = random(-WIDTH,WIDTH)
        self.x7 = random(-WIDTH,WIDTH)
        self.x8 = random(-WIDTH,WIDTH)
        self.x9 = random(-WIDTH,WIDTH)

        tb = 50
        self.y0 = random(tb,HEIGHT-tb)
        self.y1 = random(tb,HEIGHT-tb)
        self.y2 = random(tb,HEIGHT-tb)
        self.y3 = random(tb,HEIGHT-tb)
        self.y4 = random(tb,HEIGHT-tb)
        self.y5 = random(tb,HEIGHT-tb)
        self.y6 = random(tb,HEIGHT-tb)
        self.y7 = random(tb,HEIGHT-tb)
        self.y8 = random(tb,HEIGHT-tb)      
        self.y9 = random(tb,HEIGHT-tb)
              
        self.x = range(10)
        self.x[0] = self.x0
        self.x[1] = self.x1
        self.x[2] = self.x2
        self.x[3] = self.x3
        self.x[4] = self.x4
        self.x[5] = self.x5
        self.x[6] = self.x6
        self.x[7] = self.x7
        self.x[8] = self.x8
        self.x[9] = self.x9
              
        ###factors to make a move
        self.v = 15
        self.a = -0.1*self.v
      
        self.check = 0
        self.c = 0
 
    def move(self):
        self.v += self.a
        self.check += self.c
                 
        ###stop and then move again
        if self.v < 0:
            self.v = 0
            self.a = 0
            self.c = 1
       
        if self.check == 30:
            self.v = 15
            self.a = -0.1*self.v
            self.check = 0
      
       ###to move the centers of blobs
        for i in range(10):
            self.x[i] += self.v * 0.5 * (i+1)
          
            ###borders              
            if self.x[i] > WIDTH:
                self.x[i] = 0
            if self.x[i] > WIDTH:
                self.x[i] = 0
  
    def ball(self, d, r, g, b):                               
        y = range(10)
        y[0] = self.y0
        y[1] = self.y1
        y[2] = self.y2
        y[3] = self.y3
        y[4] = self.y4
        y[5] = self.y5
        y[6] = self.y6
        y[7] = self.y7
        y[8] = self.y8
        y[9] = self.y9
      
        fill(r, g, b)     
        for i in range(10):      
            ovalc(self.x[i], y[i], d, d)

 
size(400, 300)
speed(30)

def setup():
    global bb
  
    bb = Blob()

  
def draw():
    global bb
  
    bb.move()
    bb.ball(110, 1, 1, 1)
    bb.ball(100, 0.6, 0.6, 1)
    background(0, 0, 1)

def ovalc(cx, cy, w, h):
    x = cx-w/2
    y = cy-h/2
    oval(x, y, w, h)

각 방울들이 range 변수(클래스 멤버 self.x)로 조정되고 있는 데 반해, 휴지기를 설정해 주는  self.check 값이 정수로 고정되어 있어 모든 방울들이 일시에 멈추고 일시에 움직인다. self.check를 리스트 x에 관해 정의해야겠다는 결론이다. (이 결정은 총 10시간이 넘는 시도 끝에 포기되었고...)

(다음 날...)
애초에 방울들의 집합을 클래스 안에 넣었던 이유는, 그렇게 하지 않으면 draw()에서 개체별로 방울들을 그리게 되어 원치않은 윤곽선(큰 원)이 남는다고 생각했기 때문이었다. 하지만 아래와 같이 별개의 for 구문을 써서 그리게 되면(ball()) 이 문제가 해결된다. 그러므로 굳이 클래스 안에서 클래스 멤버를 리스트로 만들 이유가 없다. (사실, 아니라면 클래스를 이용해서 얻는 효용이 무엇이란 말인가... 어제의 조악한 코드를 보라. 하나의 판단 착오가 엄청난 삽질을 가져왔음을 알 수 있다.)
v0.0의 코드를 그대로 적용하되, 클래스 외부에서 클래스 멤버에 접근하는 (친숙한) 방식으로 코딩한 다음, 클래스를 보다 깔끔하게 만들기 위해 메쏘드들을 단지 재정리하기만 했다.
 

# hirmes_blobs01_2.1

class Blob:
    def __init__(self,x):      
        self.x = x
        tb = HEIGHT/10
        self.y = random(tb, HEIGHT-tb)
       
        self.v = 20
        self.a = -0.1*self.v
       
        self.check = 0
        self.c = 0
       
    def move(self, m):
        self.v += self.a
        self.x += self.v * m

        ###borders    
        if self.x > WIDTH:
            self.x = 0
        if self.x < 0:
            self.x = WIDTH 
   
    def pause(self, p):
        self.check += self.c
       
        if self.v <= 0:
            self.v = 0
            self.a = 0
            self.c = 1

        if self.check == 20 * p:
            self.v = 20
            self.a = -0.1*self.v
            self.check = 0
            self.c = 0
       
    def ball(self, d, r, g, b):                   
        fill(r, g, b)
        ovalc(self.x, self.y, d, d)
       
def ovalc(cx, cy, w, h):
    x = cx-w/2
    y = cy-h/2
    oval(x, y, w, h)  
       
      
size(600, 300)
speed(60)


def setup():
    global bb
   
    bb = range(10)
    b = range(10)
   
    for i in range(10):
        b[i] = random(WIDTH)   
        bb[i] = Blob(b[i])
   
def draw():
    global bb

    m = range(10)
    p = range(10)
   
    for i in range(10):
        m[i] = (i+1)*0.5       
        p[i] = i+1
       
   
    background(0, 0, 1)
   
    for i in range(10):       
        bb[i].move(m[i])
        bb[i].pause(p[i])
        bb[i].ball(120, 1, 1, 1)

    for i in range(10):
        bb[i].ball(110, 0.6, 0.6, 1)

m과 p에 의해 방울들이 움직이는 속력(거리)과 멈추는 시간(차례)에 변화를 줄 수 있다. 비로소 뭔가 내어 놓을 수 있는 코드가 된 것 같다.
다시 한 번 짚어 보면, 윤곽선을 남기지 않는 문제는 class 내에서 그리는 메쏘드를 별도로 정의해 주는 것만으로 완전히 해결되었던 것이다.

사용자 삽입 이미지

'Code > NodeBox' 카테고리의 다른 글

David Hirmes - lines14  (0) 2007.07.31
David Hirmes - lines02  (0) 2007.07.25
splash_class_multi  (0) 2007.07.13
splash_class  (0) 2007.07.13
progress_class  (0) 2007.07.12
posted by maetel
2007. 7. 13. 17:52 Code/NodeBox
사용자 삽입 이미지
Splash를 여러 개 만들기.
초기 위치와  터지는 위치를 설정하여 여러 개의 물방울을 만들자.

from math import sin, cos, radians

def ovalc(cx, cy, w, h):
    x = cx-w/2
    y = cy-h/2
    oval(x, y, w, h)

class Splash:
    def __init__(self,x,y,p):
        self.f = 0
        self.x = x
        self.y = y
        self.p = p

        self.d = range(6)
        self.hit = 0
            
    def fall(self):
        self.f += 1
        
        if self.y <= self.p:
            self.y = self.f*10        
            ovalc(self.x, self.y, 20, 20)


        if (self.y > self.p) & (self.hit==0):
            for i in range(6):
                self.d[i] = Drop(self.x,self.p,i*60)
                    
            self.hit = 1
        
        if self.hit==1:
            for i in range(6):
                k = self.d[i]
                k.scatter()

            
class Drop:       
    def __init__(self,x,p,a):
        self.f = 0
        self.x = x
        self.p = p
        self.a = a
        
    def scatter(self):
        r = 2*self.f
        self.f += 1
        a = self.a
        
        x = self.x + r*cos(radians(a))
        y = self.p + r*sin(radians(a))             
 
        ovalc(x, y, 10, 10)

size(300,300)
speed(150)

def setup():
    global c
    global c0
    global c1
    global c2
    global c3
    global c4
 
    c = range(5)   
    c[0] = Splash(50,0,100)
    c[1] = Splash(100,0,250)
    c[2] = Splash(150,0,150)
    c[3] = Splash(200,0,100)
    c[4] = Splash(250,0,200)
    
    c0 = c[0]
    c1 = c[1]
    c2 = c[2]
    c3 = c[3]
    c4 = c[4]
    
def draw():
    global c
    global c0
    global c1
    global c2
    global c3
    global c4
   
    c0.fall()
    c1.fall()
    c2.fall()
    c3.fall()
    c4.fall()

Drop 클래스의 self.x 와 self.y 는 Splash 클래스의 것들과 다르다.
메쏘드 fall에서 Drop 클래스의 인스턴스를 생성할 때 인수를 클래스 멤버로 입력하면, 결과적으로 다른 클래스의 멤버에 접근할 수 있게 된다.

'Code > NodeBox' 카테고리의 다른 글

David Hirmes - lines02  (0) 2007.07.25
David Hirmes - blobs01  (0) 2007.07.18
splash_class  (0) 2007.07.13
progress_class  (0) 2007.07.12
popping_1.1  (0) 2007.07.09
posted by maetel
2007. 7. 13. 16:40 Code/NodeBox
splash 예제를 두 개의 class를 써서 코딩하기

from math import sin, cos, radians

def ovalc(cx, cy, w, h):
    x = cx-w/2
    y = cy-h/2
    oval(x, y, w, h)

class Splash:
    def __init__(self):
        self.f = 0
        self.x = 0
        self.y = 0

        self.d = range(6)
        self.hit = 0
            
    def fall(self):
        self.x = WIDTH/2
        self.f += 1
        
        if self.y <= HEIGHT/2:
            self.y = self.f*10        
            ovalc(self.x, self.y, 20, 20)


        if (self.y > HEIGHT/2) & (self.hit==0):
            for i in range(6):
                self.d[i] = Drop(i*60)
                    
            self.hit = 1
        
        if self.hit==1:
            for i in range(6):
                ttt=self.d[i]
                ttt.scatter()
 
            
class Drop:       
    def __init__(self,a):
        self.f = 0
        self.a = a
        
    def scatter(self):
        r = 2*self.f
        self.f += 1
        a = self.a
        
        x = WIDTH/2 + r*cos(radians(a))
        y = HEIGHT/2 + r*sin(radians(a))             
 
        ovalc(x, y, 10, 10)


size(300,300)
speed(150)

def setup():
    global c    
    c = Splash()
    
def draw():
    global c
    c.fall()

lesson 1. class를 range 변수로 선언하는 것이 가능하다. (class member를 range의 순차번호를 매개로 했다.)
lesson 2. 어떠한 사건이 일어난 첫순간을 인식하여 사용할 때 쓰이는 pattern을 배웠다. (상기 코드의 self.hit 변수)

'Code > NodeBox' 카테고리의 다른 글

David Hirmes - blobs01  (0) 2007.07.18
splash_class_multi  (0) 2007.07.13
progress_class  (0) 2007.07.12
popping_1.1  (0) 2007.07.09
popping_1.0 (수정 중)  (0) 2007.07.06
posted by maetel
2007. 7. 12. 19:05 Code/NodeBox
progress 예제를 class를 써서 코딩하기

#1. 클래스 멤버를 동적으로 호출한다.
class Progress:
    def __init__(self):
        self.f= 0
        self.x= 0
        self.y= 0
                    
    def march(self):
        self.f+=1
        self.x = self.f*10
        
        if self.x > WIDTH:
            self.f = 0
            self.y += 50
        if self.y > HEIGHT:
            self.f = 0    
            self.y = 0
        
    def x(self):
        return self.x

    def y(self):
        return self.y
        
p = Progress()
#print p.march()

size(200,200)
speed(20)

def setup():
    global p
    p = Progress()
     
def draw():    
    global p
    p.march()

    fill(0)
    rect (p.x, p.y, 10, 10)          
 

#2. draw()에서 Progress.march()를 호출하므로 y의 초기값을  밖으로 빼 주어야 한다.
이 때, x는 self.f를 매개변수로 하므로 method 안에서 선언해도 상관이 없다.
class Progress:
    def __init__(self):
        self.f = 0
        self.y = 0
        
    def march(self):
        x = self.f*10
        self.f += 1
       
        if x > WIDTH:
            self.f = 0
            self.y+=50
           
        if self.y > HEIGHT:
            self.f = 0   
            self.y=0
           
        rect (x, self.y, 10, 10)


p = Progress()

size(200,200)
speed(20)

def setup():
    global p
    p = Progress()
    
def draw():   
    global p

    fill(0)     
    p.march()

class 안의 method에서 선언된 변수는 외부에서 직접 호출할 수 없다. 이에 대해 더 확실히 정리할 것!

'Code > NodeBox' 카테고리의 다른 글

splash_class_multi  (0) 2007.07.13
splash_class  (0) 2007.07.13
popping_1.1  (0) 2007.07.09
popping_1.0 (수정 중)  (0) 2007.07.06
popping_0.0  (0) 2007.07.06
posted by maetel
2007. 7. 11. 20:37 Code/Python
이강성 <파이썬> 379p - 생성자와 소멸자

from time import time, ctime, sleep

class Life:
    def __init__(self):
        self.birth = ctime()
        print 'Birthday', self.birth
    def __del__(self):
        print 'Deathday', ctime()
        
def test():
    mylife = Life()
    print 'Sleepling for 3 sec'
    sleep(3)
    
test()

실행하면
Birthday Wed Jul 11 20:29:36 2007
Sleepling for 3 sec
Deathday Wed Jul 11 20:29:39 2007


test 함수가 불리면서 Life 클래스 인스턴스가 하나 생성된다. 이때 자동으로 __init__ 함수가 호출되어 Birthday를 츨력한다. 3초 후에 test 함수가 종료하면서 (mylife는 지역 이름이므로 함수가 종료되면서 사라진다.) 인스턴스가 소멸된다. 이때 자동으로 __del__ 함수가 호출된다.

'Code > Python' 카테고리의 다른 글

2차원 행렬 테스트  (0) 2007.08.03
Lists  (0) 2007.08.01
posted by maetel
2007. 7. 11. 14:34 Computation/Language
ref. Python tutorial 9. Classes

The class inheritance mechanism allows multiple base classes, a derived class can override any methods of its base class or classes, and a method can call the method of a base class with the same name. Objects can contain an arbitrary amount of private data.

In Python, all data types are objects.

A namespace is a mapping from names to objects. Name spaces are created at different moments and have different lifetimes.
The word attribute is for any name following a dot. Attributes may be read-only or writable.
A scope is a textual region of a Python program where a namespace is directly accessible.

Assignments always go into the innermost scope. Assignments do not copy data -- they just bind names to objects.

A class object is basically a wrapper around the contents of the namespace created by the class definition.

Class objects support two kinds of operations: attribute references and instantiation.
Attribute references
use the standard syntax used for all attribute references in Python: obj.name.
Class instantiation uses function notation. Just pretend that the class object is a parameterless function that returns a new instance of the class.

The only operations understood by instance objects are attribute references. There are two kinds of valid attribute names, data attributes and methods.
Data attributes
correspond to "instance variables'' in Smalltalk, and to "data members'' in C++.
A method is a function that "belongs to'' an object. The special thing about methods is that the object is passed as the first argument of the function.

Any function object that is a class attribute defines a method for instances of that class.

The global scope associated with a method is the module containing the class definition. (The class itself is never used as a global scope!) Functions and modules imported into the global scope can be used by methods, as well as functions and classes defined in it. Usually, the class containing the method is itself defined in this global scope.



ref. 이강성 <열혈강의 파이썬(Python)> 개정판 Ver.2: 12 클래스, 프리렉

파이썬의 클래스는 새로운 이름 공간을 지원하는 단위이다. 이 이름 공간에는 함수와 변수가 포함될 수 있다. 클래스는 하나 이상의 인스턴스 객체를 생성하는 틀과 같다.
(클래스 자체가 이름 공간을 가지지만, 각각의 인스턴스도 독립적인 이름 공간을 가진다. ->) 동적으로 클래스 외부에서 멤버를 생성할 수 있다.

Class : class 문으로 정의되며, 멤버와 메쏘드를 가지는 객체
Class Object
Class Instance : 클래스를 호출하여 만들어지는 객체
Class Instance Object
Member : 클래스가 갖는 변수
Method : 클래스 내에 정의된 함수
Attribute : 멤버와 메쏘드 전체. 즉, 이름 공간의 이름 전체.
Super Class = Base Class
Sub Class = Derived Class

> Features of Classes in OOP
Inheritance 상속: (A 클래스를 수퍼 클래스로 하는 클래스 B를 생성하였다면 B 'is-a' A 관계라고 함.)
Multiple Inheritance 다중 상속: 두 개 이상의 수퍼 클래스로부터 상속받는 것
Polymorphism 다형성: 상속 관계 내의 다른 클래스의 인스턴스들이 같은 멤버 함수 호출에 대해 각각 다르게 반응하도록 하는 기능
Encapsulation 정보 은닉: 메쏘드와 멤버를 클래스 내에 포함시키고 외부에서 접근 가능하도록 인터페이스만을 공개하고 다른 속성들은 내부에 숨기는 것
Composition 합성: 어떤 객체가 다른 객체에 포함되어 활용되는 것 (x라는 객체가 클래스 A안에 포함되어 A의 각종 메쏘드를 구현하는데 사용된다면, A가 x를 포함하므로 'has-a'관계라고 함.)

self: 메쏘드를 정의할 때 사용하는 첫 인수. 자신의 인스턴스 객체를 가리키는 레퍼런스이다.
- 모든 메쏘드는 반드시 self를 첫 인수로 받아야 한다. (이 self를 이용하여 클래스의 이름 공간에 접근해야 하기 때문이다.)
- 지역(local) 이름은 함수가 종료되면 리턴과 동시에 없어지므로 객체 이름 공간에 값을 저장해 두지 않으면 나중에 사용할 수 없다.
- 메쏘드를 인스턴스 객체를 통하여 직접 호출할 때는 첫번째 인수인 self는 없다고 생각하면 된다.
- 클래스의 멤버나 메쏘드를 참조하려면 언제나 self를 이용해야 한다.

Unbound Class Method 호출: 클래스 객체를 이용하여 메쏘드를 호출하는 것
Bound Instance Method 호출: 인스턴스를 통하여 자동으로 self인수를 전달하는 방식

Static Method 정적 메쏘드: 인스턴스 객체를 생성하지 않고도, 또는 인스턴스 객체를 이용하지 않고도 클래스 이름을 이용하여 직접 호출할 수 있는 메쏘드
Class Method

Class Member - 메쏘드 바깥에 정의된다.
Instance Member - 메쏘드 내부에서 self를 이용하여 정의된다.

Constructor 생성자: 인스턴스 객체가 생성될 때 초기화를 위해서 자동적으로 불려지는 초기화 함수
Destructor 소멸자: 인스턴스 객체가 사용이 끝나서 메모리에서 해체될 때 자원 해제를 위해서 자동으로 호출되는 함수

Reserved Words 예약어: 미리 어떤 기능이 정의된 경우
    eg1. __init__
    eg2. __del__







'Computation > Language' 카테고리의 다른 글

Python tutorials  (0) 2008.02.24
Using Python for CGI programming  (0) 2007.07.11
Python  (0) 2007.06.26
features of object-oriented programming  (0) 2007.06.20
내 컴퓨터에서 Processing의 source code 보기  (0) 2007.04.19
posted by maetel
2007. 3. 16. 10:16 Computation/Language
61p
객체 마을로의 여행

constructor(생성자), method(함수), property(변수, 객체)
    cf. instance

절차 지향/객체 지향

 
 procedure
"프로그램이라는 것은 결국은 프로시저를 모아놓은 것"
= Subroutine or method (computer science)
(1) Same as routine, subroutine, and function. A procedure is a section of a program that performs a specific task.
(2) An ordered set of tasks for performing some action.
   
     subroutine http://en.wikipedia.org/wiki/Subroutine
    a portion of code within a larger program, which performs a specific task and is relatively independent of the remaining code.   

 object
Generally, any item that can be individually selected and manipulated. This can include shapes and pictures that appear on a display screen as well as less tangible software entities. In object-oriented programming, for example, an object is a self-contained entity that consists of both data and procedures to manipulate the data.
http://en.wikipedia.org/wiki/Object_%28computer_science%29
http://java.sun.com/docs/books/tutorial/java/concepts/object.html

 method
 In object-oriented programming, a procedure that is executed when an object receives a message. A method is really the same as a procedure, function , or routine in procedural programming languages. The only difference is that in object-oriented programming, a method is always associated with a class.

 instance
(1) 일반적으로 어떤 집합에 대해서, 그 집합의 개별적인 요소. 객체 지향 프로그래밍(OOP)에서, 어떤 등급에 속하는 각 객체를 인스턴스라고 한다. 예를 들면 ‘목록(list)’이라는 등급을 정의하고 그 다음에 ‘본인 목록(my list)’이라는 객체를 생성(기억 장치 할당)하면 그 등급의 인스턴스가 생성된다. 또한 변수가 포함되어 있는 어떤 논리식의 변수에 구체적인 값을 대입하여 식을 만들면 원래 식의 인스턴스가 만들어진다. 이런 의미에서 인스턴스를 실현치라고 한다.
(2) 프로그램 작성 언어 에이다(Ada)에서 매개 변수를 사용해서 절차를 일반적으로 정의한 범용체(generic package)에 대해, 그것으로부터 도출한 구체적인 실체.

 constructor 생성자 生成子
객체 지향 프로그래밍(OOP:objective-oriented programming)에서 쓰이는 객체 초기화 함수. 객체의 생성 시에만 호출되어 메모리 생성과 동시에 객체의 데이터를 초기화하는 역할을 한다.
: 객체를 처음 생성할 때 자동으로 만들어지는 함수.
<=
class의 속성을 정의해 주는 것이 constructor(생성자)이다.



'Computation > Language' 카테고리의 다른 글

features of object-oriented programming  (0) 2007.06.20
내 컴퓨터에서 Processing의 source code 보기  (0) 2007.04.19
Java tutorials  (0) 2007.02.28
The Java™ Tutorials  (0) 2007.02.28
The Java Technology  (0) 2007.02.28
posted by maetel