패키지 만들기와 사용하기 Creating and Using Packages
프로그래머들은, 타입들을 보다 쉽게 찾고 사용하게 하기 위하여, 이름 짓기에서 혼동이 안생기도록 하기 위하여, 관련 있는 타입들의 그룹들을 패키지로 묶습니다.
To make types easier to find and use, to avoid naming conflicts, and to control access, programmers bundle groups of related types into packages.
정의: package는 access protection 및 name space 관리를 제공하는, 관련된 타입들의 그루핑입니다.
types은 classes, interfaces, enumerations 및 annotation types를 가리킨다는 점을 주목하십시오.
Enumerations 및 annotation types은 각각 특별한 종류의 classes 및 interfaces로, 그래서 types들은 자주 이 단원에서 간단하게 classes 및 interfaces로 언급됩니다.
Definition: 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.
The types that are part of the Java platform are members of various packages that bundle classes by function: fundamental classes are in java.lang
, classes for reading and writing (input and output) are in java.io
, and so on. You can put your types in packages too.
Suppose you write a group of classes that represent graphic objects, such as circles, rectangles, lines, and points. You also write an interface, Draggable
, that classes implement if they can be dragged with the mouse.
//in the Draggable.java file public interface Draggable { ... } //in the Graphic.java file public abstract class Graphic { ... } //in the Circle.java file public class Circle extends Graphic implements Draggable { . . . } //in the Rectangle.java file public class Rectangle extends Graphic implements Draggable { . . . } //in the Point.java file public class Point extends Graphic implements Draggable { . . . } //in the Line.java file public class Line extends Graphic implements Draggable { . . . }
You should bundle these classes and the interface in a package for several reasons, including the following:
- You and other programmers can easily determine that these types are related.
- You and other programmers know where to find types that can provide graphics-related functions.
- The names of your types won't conflict with the type names in other packages because the package creates a new namespace.
- You can allow types within the package to have unrestricted access to one another yet still restrict access for types outside the package.
'Java 배우기' 카테고리의 다른 글
Naming a Package 패키지 이름짓기 (0) | 2016.01.24 |
---|---|
Creating a Package 패키지 만들기 (0) | 2016.01.24 |
Lesson: Packages 단원: 패키지 (0) | 2016.01.24 |
Questions and Exercises: Generics (0) | 2016.01.24 |
Restrictions on Generics (0) | 2016.01.24 |
댓글