Latest Changes

Differences between version EMPTY and #14253

0a1,174
> ====== 클래스 ======
> 
> 이미 객체 지향 프로그래밍에 대해 친숙하다고 가정하고 클래스의 구조에 대해 빠르게 설명하겠습니다 :
> 
> <code haxe>
> 	package my.pack;
> 	/*
> 		my.pack.MyClass 라는 클래스를 정의합니다.
> 	*/
> 	class MyClass {
> 		// ....
> 	}
> </code>
> 
> 클래스는 여러 //속성//과 //메서드//를 가질 수 있습니다.
> 
> <code haxe>
> 	package my.pack;
> 
> 	class MyClass {
> 
> 		var id : Int;
> 
> 		static var name : String = "MyString";
> 
> 		function foo() : Void {
> 		}
> 
> 		static function bar( s : String, v : Bool ) : Void {
> 		}
> 	}
> </code>
> 
> 속성과 메서드는 다음과 같은 //플래그//들을 가질 수 있습니다 :
> 
>   * **static** : 이 클래스의 //인스턴스//가 갖지 않고 클래스 자신이 갖는 필드입니다. Static 식별자는 클래스 안에서는 바로 사용될 수 있지만 클래스 바깥에서는 클래스 이름과 함께 사용되어야 합니다.( 예 : ''my.pack.MyClass.name'' )
>   * **dynamic**: 동적으로 재설정 될 수 있는 필드입니다.
>   * **override**: 상위 클래스의 멤버를 오버라이드한 필드입니다.
>   * **public** : 클래스의 외부에서 접근할 수 있는 필드입니다.
>   * **private** : 클래스 자신이나 이 클래스를 상속받는 클래스에서만 접근할 수 있는 필드입니다.
> 클래스의 내부 접근이 허용되지 않음이 보장됩니다.
> **기본적으로, 모든 필드는 ''private'' 필드입니다**. 이는 Java나 PHP등 여러 객체지향 언어에서 사용되는 **protected** 키워드에 해당합니다.
> 
> 모든 클래스 변수는 **무조건** 타입이 선언되어야 합니다( 사용할 값의 타입을 알 수 없는 경우는 ''Dynamic'' 타입을 사용하면 됩니다 ). 함수 인자와 반환형은 선택적이지만 그 것들도 엄격한 타입 검사가 이루어지는데, 타입 추론에서 소개하겠습니다.
> 
> 정적변수 외에는 초기화 값을 가질 수 //없습니다//. 정적변수는 초기화 값을 가질 수 //있지만// 필수는 아닙니다.
> 
> ====== 생성자 ======
> 
> 클래스는 비 정적함수인 ''new''라고 불리는 단 하나의 생성자만을 가질 수 있습니다. 이는 클래스 함수를 호출하는 키워드로도 사용됩니다 :
> 
> <code haxe>
> 	class Point {
> 		public var x : Int;
> 		public var y : Int;
> 
> 		public function new() {
> 			this.x = 0;
> 			this.y = 0;
> 		}
> 	}
> </code>
> 
> 생성자 인자설정 & 오버로딩 :
> 
> <code haxe>
> 	public function new( x : Int, ?y : Int ) {
> 		this.x = x;
> 		this.y = (y == null) ? 0 : y; // "y" is optional
> 	}
> </code>
> 
> ====== 클래스 상속 ======
> 
> 클래스가 선언될 때에 하나의 클래스를 //확장//할 수 있고 여러 클래스나 인터페이스를 //구현//할 수 있습니다. 하나의 클래스에서 동시에 여러 //타입//을 상속받을 수 있고, 그들과 동일하게 사용될 수 있습니다 :
> 
> <code haxe>
> 	class D extends A, implements B, implements C {
> 	}
> </code>
> 
> D의 모든 //인스턴스//는 D //타입//을 갖지만, A, B나 C //타입//이 필요한 곳에서도 사용될 수 있습니다. 따라서 D의 모든 //인스턴스//는 A, B, C, D //타입//을 다 갖습니다.
> 
> ===== Extends =====
> 
> When //extending// a class, your class //inherits// from all //public// and //private// non-static fields. You can then use them in your class as if they where declared here. You can also //override// a method by redefining it with the same number of arguments and types as its //superclass//. Your class //can not// inherit //static// fields.
> 
> When a //method// is //overridden//, then you can still access the //superclass// method using ''super'' :
> 
> <code haxe>
> 	class B extends A {
> 		override function foo() : Int {
> 			return super.foo() + 1;
> 		}
> 	}
> </code>
> 
> In your class constructor you can call the //superclass// constructor using also ''super'' :
> 
> <code haxe>
> 	class B extends A {
> 		function new() {
> 			super(36,"");
> 		}
> 	}
> </code>
> 
> ===== Implements =====
> 
> When //implementing// a class or an interface, your class is //required// to implement all the fields //declared// or //inherited// by the class it implements, with the same type and name. However the field might already be //inherited// from a superclass.
> 
> 
> ===== Interfaces =====
> 
> An //Interface// is an abstract type. It is declared using the ''interface'' keyword. By default, all interface fields are //public//. Interfaces cannot be instantiated.
> 
> <code haxe>
> 	interface PointProto {
> 		var x : Int;
> 		var y : Int;
> 		function length() : Int;
> 	}
> </code>
> 
> An interface can also //implement// one or several interfaces :
> 
> <code haxe>
> 	interface PointMore implements PointProto {
> 		function distanceTo( p : PointProto ) : Float;
> 	} 
> </code>
> 
> ===== Helper Classes =====
> In Haxe, it is possible to have more than one class definition per class file:
> 
> <code haxe>
> // both definitions in Foo.hx
> class Foo { ... }
> class FooHelper { ... }
> </code>
> 
> This is fairly common in many object oriented languages such as Java.  However, unlike other such languages, Haxe also allows for these internal helper classes to be publicly available outside of the main class.  By importing the main class, the helper class becomes available:
> 
> <code haxe>
> // in Bar.hx
> import Foo;
> class Bar{
>      var b:FooHelper;
> }
> </code>
> 
> The helper class can also be made accessible via an extended package declaration:
> 
> <code haxe>
> // in Bar.hx
> class Bar{
>      var b:Foo.FooHelper;
> }
> </code>
> 
> The use of public internal helper classes is typically not a recommended practice in most languages.  Since helper class names do not correspond with their  .hx file names, they can be harder to find in source trees.  
> 
> HaXe lets you mark an internal helper class with the //private// keyword, in the same way that fields are marked:
> <code haxe>
> // both definitions in Foo.hx
> class Foo { ... }
> private class FooHelper { ... }
> </code>
> 
> This prevents the internal helper class from being accessed outside of the main class.
> 
> Unless there is a good reason for their use, consider placing each public class definition in its own .hx file, or make the internal class private, to prevent its definitions being included (and possibly causing a name conflict) when the main class is imported.
> 
> «« [[/ref/type_infer]] - [[/ref/type_params]] »»
\ No newline at end of file

	
Ver Date Entry Lg User Action
#19360 2013-05-13 17:42:34 doc/libraries en Confidant View | Diff
#19359 2013-05-13 05:01:15 manual/macros/advanced en jason View | Diff
#19358 2013-05-12 02:55:03 com/ide en MarcWeber View | Diff
#19357 2013-05-11 05:26:13 ref/conditionals jp shohei909 View | Diff
#19356 2013-05-10 09:29:15 manual/completion en jason View | Diff
#19355 2013-05-09 00:24:39 download/manual_install/leopard en JLM View | Diff
#19354 2013-05-09 00:10:46 download/manual_install/leopard/justinsbuildnotes en JLM View | Diff
#19353 2013-05-08 18:42:04 com/news en ncannasse View | Diff
#19352 2013-05-08 18:12:08 manual/haxe3 en ncannasse View | Diff
#19351 2013-05-08 18:09:11 manual/haxe3 en Simn View | Diff
#19350 2013-05-08 18:04:19 manual/haxe3 en ncannasse View | Diff
#19349 2013-05-08 15:57:29 doc/haxelib/haxelib2 en jason View | Diff
#19348 2013-05-08 15:57:29 doc/haxelib/haxelib2 en jason Changed title from Haxelib 2 to Haxelib 3
#19347 2013-05-08 15:21:08 manual/haxe3/features jp shohei909 View | Diff
#19346 2013-05-08 15:15:14 manual/haxe3/features en shohei909 View | Diff
#19345 2013-05-08 11:51:53 doc/haxelib/haxelib2 en back2dos View | Diff
#19344 2013-05-08 11:28:55 api/flash/display/graphics kr api View | Diff
#19343 2013-05-08 11:28:36 api/flash kr api View | Diff
#19342 2013-05-08 11:28:03 api kr api View | Diff
#19341 2013-05-08 11:27:08 api ro api View | Diff

Previous | Next