TAILIEUCHUNG - HandBooks Professional Java-C-Scrip-SQL part 110

Tham khảo tài liệu 'handbooks professional java-c-scrip-sql part 110', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | All ancestor initialization calls should be usable on a class s instance. The difficulty here is guaranteeing that the class s own initialization will not be skipped. Objective-C programmers have adopted the following design patterns to ensure these conditions are always met Your class may have several initialization methods it is conventional to name those methods starting with init. The most specialized initializer usually the one with the most parameters is called the designated initializer and has a special role all your class s other initializers should call it. Your class should override the parent class s designated initializer. Your designated initializer should call the parent class s designated initializer. The rationale for these guidelines is presented in the next section in the context of a concrete example. Sample code for initialization The following code illustrates the design pattern you should follow to ensure correct initialization of your objects. In the example you are writing the subclass MyClass. We assume the parent class follows the same rules we illustrate in the subclass. 1 @interface Parent Object 2 int i 3 4 - id init 5 - id initWithI int val 6 @end 7 8 @interface MyClass Parent 9 int j 10 11 - id initWithI int iVal 12 - id initWithI int iVal andJ int jVal 13 @end 14 15 @implementation MyClass 16 - id initWithI int iVal 17 return self initWithI iVal andJ 42 18 19 - id initWithI int iVal andJ int jVal 20 if self super initWithI iVal 21 j jVal 22 23 return self 24 25 @end Line 4. All initializers return id. This class has a simple -init method taking no parameters. It calls funnels to -initWithI passing in a default value. Line 5. Parent provides another initializer initWithI which lets you specify the value of the field i. This is the designated initializer. Line 11. MyClass overrides covers its parent s designated initializer. Always do this in your classes. If you don t cover a parent s designated initializer code such as .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.