본문 바로가기

C++

[C++?] 인스턴스와 객체의 차이점? instance vs object

A class is a blueprint which you use to create objects. An object is an instance of a class - it's a concrete 'thing' that you made using a specific class. So, 'object' and 'instance' are the same thing, but the word 'instance' indicates the relationship of an object to its class.

 

This is easy to understand if you look at an example. For example, suppose you have a class House. Your own house is an object and is an instance of class House. Your sister's house is another object (another instance of class House).

 

 

클래스 객체를 생성할 때 사용 하는 설계도와 같습니다. 하나의 객체는 그 클래스의 인스턴스 - 특정한 클래스를 이용하여 만든 실체가 있는 '어떤것' 입니다. 그러니까 '객체'와 '인스턴스'는 같은 것이지만, '인스턴스' 라는 용어는 객체와 그의 클래스에 대한 관계를 가리킵니다.

 

예시를 보면 이해 하기가 쉬울 겁니다. 예를 들어, 이라는 클래스가 있습니다. 당신 소유의 집은 객체이면서 이라는 클래스의 인스턴스 입니다. 여동생의 집은 또다른 객체( 이라는 클래스의 또다른 인스턴스) 입니다.

 

// Class House describes what a house is
class House {
    // ...
}

// You can use class House to create objects (instances of class House)
House myHouse = new House();
House sistersHouse = new House();

 

The class House describes the concept of what a house is, and there are specific, concrete houses which are objects and instances of class House.

Note: This is exactly the same in Java as in all object oriented programming languages.

 

 

 이라는 클래스는 집이 무엇인지에 대한 개념을 기술합니다. 그리고 내 집, 여동생 집, ... 즉 집들 은 구체적이고 실체가 있는 객체 이면서 집 이라는 클래스의 인스턴스 입니다.

참고: 이 개념은 다른 모든 객체지향프로그래밍 언어에서 그렇듯 자바에서도 정확히 같습니다.

 

출처 : https://stackoverflow.com/questions/1215881/the-difference-between-classes-objects-and-instances

 

The difference between Classes, Objects, and Instances

What is a class, an object and an instance in Java?

stackoverflow.com

그리고 구조적 프로그래밍의 관점에서 라고는 하지만 니 시간을 그렇게 쓸 만큼 둘 사이에는 큰 차이가 없으니 거기 쓸 시간과 노력을 '개발'에 더 쏟으라는 의견도 있었다.. ^^ 네..

 

그러니까 위의 예시로 따지자면 House 라는 클래스의 인스턴스! 인 myHouse, sisterHouse. 그리고 각각은 객체라고 지칭. 정도 로 이해 하면 될듯.

나는 객체인데, 이름은 myHouse고, House 라는 클래스의 인스턴스야~!!

쫌 이해 되나?