이름공간

개체를 구분할 수 있는 범위

이름공간 또는 네임스페이스(영어: namespace)는 개체를 구분할 수 있는 범위를 나타내는 말로 일반적으로 하나의 이름 공간에서는 하나의 이름이 단 하나의 개체만을 가리키게 된다.

저명한 예는 다음을 포함한다:

  • 파일 시스템은 파일에 이름을 할당하는 이름공간이다.[1]
  • 일부 프로그래밍 언어들은 이름공간 안에 변수함수를 조직한다.[2][3][4] 컴퓨터 프로그래밍 언어인 C에서는 전역 지역 공간과 지역 이름 공간이라는 이름 공간에 대한 개념이 있는데, 각각의 이름 공간에서는 같은 변수나 함수 이름을 사용할 수 없지만, 영역이 다르면 변수나 함수명이 같을 수도 있다. C++와 Java 프로그래밍 언어에서는 이름 공간을 명시적으로 지정하여 사용할 수 있다.
  • 컴퓨터 네트워크분산 시스템은 이름을 컴퓨터, 프린터, 웹사이트, (원격) 파일 등의 자원에 할당한다.

네이밍 시스템 편집

이름공간의 이름은 이름공간 식별자와 로컬 이름으로 구성된다. 이름공간의 이름은 일반적으로 로컬 이름에 대한 두문자로 적용된다.

ABNF 형식으로는 다음과 같이 나타낸다.

name = <namespace identifier> separator <local name>

편집

이름공간의 이름의 예
컨텍스트 이름 이름공간 식별자 로컬 이름
경로 /home/user/readme.txt /home/user (path) readme.txt (file name)
도메인 네임 www.example.com example.com (domain) www (host name)
C++ std::array std array
UN/LOCODE US NYC US (country) NYC (locality)
XML xmlns:xhtml="http://www.w3.org/1999/xhtml"
<xhtml:body>
http://www.w3.org/1999/xhtml body
$DBI::errstr DBI $errstr
자바 java.util.Date java.util Date
URN (URN) urn:nbn:fi-fe19991055 urn:nbn (National Bibliography Numbers) fi-fe19991055
핸들 시스템 10.1000/182 10 (Handle naming authority) 1000/182 (Handle local name)
디지털 객체 식별자 10.1000/182 10.1000 (publisher) 182 (publication)
MAC 주소 01-23-45-67-89-ab 01-23-45 (en:organizationally unique identifier) 67-89-ab (NIC specific)
PCI ID 1234 abcd 1234 (Vendor ID) abcd (Device ID)
USB VID/PID 2341 003f[5] 2341 (Vendor ID) 003f (Product ID)

프로그래밍에서의 예 편집

아래는 C++에 사용한 이름공간의 예이다.

#include <iostream>
using std::cout;
using std::endl;

namespace Box1{
   int boxSide = 4;
}

namespace Box2{
   int boxSide = 12;
}

int main () {
  cout << Box1::boxSide << endl;  //output 4
  cout << Box2::boxSide << endl;  //output 12
  return 0;
}

같이 보기 편집

각주 편집

  1. Adya, Atul; Bolosky, William; Castro, Miguel; Cermak, Gerald; Chaiken, Ronnie; Douceur, John; Howell, Jon; Lorch, Jacob; Theimer, Marvin; Wattenhofer, Roger (2002). 《FARSITE: Federated, Available, and Reliable Storage for an Incompletely Trusted Environment》 (PDF). Proc. USENIX Symp. on Operating Systems Design and Implementation. 2010년 7월 28일에 원본 문서 (PDF)에서 보존된 문서. The primary construct established by a file system is a hierarchical directory namespace, which is the logical repository for files. 
  2. “C# FAQ: What is a namespace”. http://en.csharp-online.net/: C# Online Net. 2013년 10월 20일에 원본 문서에서 보존된 문서. 2010년 2월 23일에 확인함. A namespace is nothing but a group of assemblies, classes, or types. A namespace acts as a container—like a disk folder—for classes organized into groups usually based on functionality. C# namespace syntax allows namespaces to be nested. 
  3. “An overview of namespaces in PHP”. 《PHP Manual》. What are namespaces? In the broadest definition namespaces are a way of encapsulating items. This can be seen as an abstract concept in many places. For example, in any operating system directories serve to group related files, and act as a namespace for the files within them. 
  4. “Creating and Using Packages”. 《Java Documentation》. Oracle. A package is a grouping of related types providing access protection and name space management. Note that types refers to classes, interfaces, enumerations, and annotation types. Enumerations and annotation types are special kinds of classes and interfaces, respectively, so types are often referred to in this lesson simply as classes and interfaces. 틀:Better source
  5. Stephen J. Gowdy. "List of USB ID's". 2013.