Classes, Top-Level Classes, and Instances Basically
Số trang: 2
Loại file: pdf
Dung lượng: 9.45 KB
Lượt xem: 14
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Lớp Array đã ẩn logic và định nghĩa (code) mà làm việc đằng sau hậu trường để xác định cách một đối tượng Array công trình và làm thế nào nó được sử dụng. Hãy suy nghĩ của một lớp học như là một tiêu bản mà từ đó các đối tượng được tạo ra. Đây là một mô tả mơ hồ của một lớp, nhưng khi bạn tiến bộ thông qua bài học này và được giới thiệu với các khái niệm nhiều hơn, thuật ngữ...
Nội dung trích xuất từ tài liệu:
Classes, Top-Level Classes, and Instances Basically < Day Day Up >Classes, Top-Level Classes, and InstancesBasically, a class is a definition or blueprint of how an object is made up and how itshould act. For example, an instance of the Array class (an Array object) can storemultiple pieces of information in numerically indexed locations (myArray[0],myArray[1], myArray[2], and so on). How can the array do this? It knows how to do thisbecause it was defined that way by the Array class. The Array class has hidden logic anddefinitions (code) that work behind the scenes to define the way an Array object worksand how its used. Think of a class as a template from which objects are created. This is avague description of a class, but as you progress through this lesson and are introduced tomore concepts, terminology, and examples, youll gain a better understanding of what aclass really is.A class generally exists to produce an instance of itself on demand. You create aninstance of a class by invoking the constructor method of that class. For example:var myArray:Array = new Array():The action to the right of the equals sign, new Array() in this example, executes theconstructor method of the Array class. You cannot use the Array class directly. You mustcreate an instance of the class to use any of its properties and methods. When creating thearray instance, the Array class creates an object and then populates it with properties andmethods. In a sense, the Array class is similar to a factory for array objects. When asked,it creates and returns an Array object.There also are classes that you can use without the need to create an instance. This typeof a class is called a top-level class. Examples of this type of class include the Math,Mouse, and Key classes. When you think about it, top-level classes make sense. Is thereever really a need to have more than one instance of the Mouse class or the Math class?With the Math class, you simply pass a number into a method and a result is returned.The Math class doesnt store any of the information that you feed it, so only one copy isneeded. On the other hand, arrays store unique data, so it wouldnt make sense to accessthe Array class directly because you would only be able to have one array.TIPSome programmers call a top-level class a singleton. < Day Day Up >
Nội dung trích xuất từ tài liệu:
Classes, Top-Level Classes, and Instances Basically < Day Day Up >Classes, Top-Level Classes, and InstancesBasically, a class is a definition or blueprint of how an object is made up and how itshould act. For example, an instance of the Array class (an Array object) can storemultiple pieces of information in numerically indexed locations (myArray[0],myArray[1], myArray[2], and so on). How can the array do this? It knows how to do thisbecause it was defined that way by the Array class. The Array class has hidden logic anddefinitions (code) that work behind the scenes to define the way an Array object worksand how its used. Think of a class as a template from which objects are created. This is avague description of a class, but as you progress through this lesson and are introduced tomore concepts, terminology, and examples, youll gain a better understanding of what aclass really is.A class generally exists to produce an instance of itself on demand. You create aninstance of a class by invoking the constructor method of that class. For example:var myArray:Array = new Array():The action to the right of the equals sign, new Array() in this example, executes theconstructor method of the Array class. You cannot use the Array class directly. You mustcreate an instance of the class to use any of its properties and methods. When creating thearray instance, the Array class creates an object and then populates it with properties andmethods. In a sense, the Array class is similar to a factory for array objects. When asked,it creates and returns an Array object.There also are classes that you can use without the need to create an instance. This typeof a class is called a top-level class. Examples of this type of class include the Math,Mouse, and Key classes. When you think about it, top-level classes make sense. Is thereever really a need to have more than one instance of the Mouse class or the Math class?With the Math class, you simply pass a number into a method and a result is returned.The Math class doesnt store any of the information that you feed it, so only one copy isneeded. On the other hand, arrays store unique data, so it wouldnt make sense to accessthe Array class directly because you would only be able to have one array.TIPSome programmers call a top-level class a singleton. < Day Day Up >
Tìm kiếm theo từ khóa liên quan:
máy tính mạng máy tính internet phần mềm ứng dụng lập trình SQL HTML sever web XMLGợi ý tài liệu liên quan:
-
Giáo án Tin học lớp 9 (Trọn bộ cả năm)
149 trang 263 0 0 -
Ngân hàng câu hỏi trắc nghiệm môn mạng máy tính
99 trang 251 1 0 -
Giáo trình Hệ thống mạng máy tính CCNA (Tập 4): Phần 2
102 trang 244 0 0 -
Bài giảng: Lịch sử phát triển hệ thống mạng
118 trang 244 0 0 -
47 trang 237 3 0
-
Đề cương chi tiết học phần Thiết kế và cài đặt mạng
3 trang 234 0 0 -
80 trang 216 0 0
-
122 trang 212 0 0
-
Giáo trình Hệ thống mạng máy tính CCNA (Tập 4): Phần 1
122 trang 210 0 0 -
Giáo trình môn học/mô đun: Mạng máy tính (Ngành/nghề: Quản trị mạng máy tính) - Phần 1
68 trang 201 0 0