1. Trang chủ
  2. » Công Nghệ Thông Tin

Lập trình Windows - Lập Trình C #- Lập Trình C Shap - Chương 3 potx

118 1.5K 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Chương Xây dựng lớp và giao diện Nội dung    Lập trình hướng đối tượng là gì? Khai báo lớp Khai báo interface     Constructor & destructor Thuộc tính (field) Method Inheritance   Protected fields Overriding method Nội dung  Polymorphism (Đa hình)     Down cast – up cast Abstract class Sealed class, nested class Interface Overview “Everything is an object! At least, that is the view from inside the CLR and the C# programming language This is no surprise, because C# is, after all, an object-oriented language The objects that you create through class definitions in C# have all the same capabilities as the other predefined objects in the system…” Apress-Accelerated C# 2008 Object-oriented Programming (OOP) Kỹ thuật lập trình truyền thống ( procedural programming):  all functionality is contained in a few modules of code (often just one)  Khó thay thế cải tiến  Kỹ thuật OOP :  Sử dụng nhiều modules of code, mỗi module cung cấp chức riêng và có thể được lập (isolated) hay thậm chí độc lập hoàn toàn với  Dễ dàng sử dụng lại module  What is an Object?     An object is a building block of an OOP application Objects in C# are created from types, just like the variables The type of an object is known by a special name in OOP, its class You can use class definitions to instantiate objects, which means creating a real, named instance of a class Cấu trúc của object  Một object gồm có:   Field Method Life Cycle of an Object Gồm giai đoạn (two important stages): ➤ Construction: đối tượng cần được khởi tạo, và được thực thi bởi hàm constructor ➤ Destruction: đối tượng bị hủy bỏ, số nhiệm vụ clean-up cần được thực thi để giải phóng nhớ  hàm destructor  Tạo lớp C#  Khai báo lớp [access modifier] class [: base class] { // class body }   Nếu ko khai báo lớp sở C# mặc định xem lớp sở object Lớp kiểu liệu tham chiếu (reference type) C# Khóa truy xuất cho class (Access modifier)  Một class có khóa truy xuất  Internal: cho phép sử dụng bên project hiện hành (default) internal class MyClass { // Class members }  Public: cho phép project bên ngoài truy xuất public class MyClass { // Class members } ... Here, currSpeed will receive the // default value of an int (zero) // Make a Car called Chuck public Car(string pn) Instance going 10 MPH { Constructors petName = pn; Car chuck = new Car(); } chuck.PrintState();... ''state'' of the Car public string petName; public int currSpeed; // A custom default constructor public Car() { petName = "Chuck"; A custom default currSpeed = 10; constructorstatic void Main(string[]... void) Mỗi class phải có nhất constructor Nếu bạn không tạo constructor cho class thỉ compiler sẽ tự động phát default constructor Cho phép overload constructor để tạo nhiều c? ?ch khởi tạo

Ngày đăng: 12/07/2014, 02:20

Xem thêm: Lập trình Windows - Lập Trình C #- Lập Trình C Shap - Chương 3 potx

TỪ KHÓA LIÊN QUAN

Mục lục

    Chương 3 Xây dựng lớp và giao diện

    What is an Object?

    Cấu trúc của object

    Life Cycle of an Object

    Tạo lớp trong C#

    Khóa truy xuất cho class (Access modifier)

    Biểu diễn interface bằng UML

    Khai báo interface

    So sánh Interface và class

    Các thành phần của class

TRÍCH ĐOẠN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w