Giáo trình hình thành ứng dụng kỹ năng gán đối tượng cho một giao diện đối lập p2
Số trang: 10
Loại file: pdf
Dung lượng: 1.35 MB
Lượt xem: 8
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:
Tham khảo tài liệu giáo trình hình thành ứng dụng kỹ năng gán đối tượng cho một giao diện đối lập p2, khoa học xã hội, thư viện thông tin phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Giáo trình hình thành ứng dụng kỹ năng gán đối tượng cho một giao diện đối lập p2 . Ngôn Ngữ Lập Trình C# // bộ khởi tạo lớp Document lấy một tham số public Document( string s) { Console.WriteLine(“Creating document with: {0}”, s); } // thực thi giao diện IStorable public void Read() { Console.WriteLine(“Implementing the Read Method for IStorable”); } public void Write( object o) { Console.WriteLine(“Implementing the Write Method for IStorable”); } public int Status { get { return status; } set { status = value; } } // thực thi ICompressible public void Compress() { Console.WriteLine(“Implementing Compress”); } public void Decompress() { Console.WriteLine(“Implementing Decompress”); } // thực thi giao diện ILoggedCompressible public void LogSavedBytes() { Console.WriteLine(“Implementing LogSavedBytes”); 183. Thực Thi Giao Diện . Ngôn Ngữ Lập Trình C# } // thực thi giao diện IStorableCompressible public void LogOriginalSize() { Console.WriteLine(“Implementing LogOriginalSize”); } // thực thi giao diện public void Encrypt() { Console.WriteLine(“Implementing Encrypt”); } public void Decrypt() { Console.WriteLine(“Implementing Decrypt”); } // biến thành viên lưu dữ liệu cho thuộc tính private int status = 0; } public class Tester { public static void Main() { // tạo đối tượng document Document doc = new Document(“Test Document”); // gán đối tượng cho giao diện IStorable isDoc = doc as IStorable; if ( isDoc != null) { isDoc.Read(); } else { Console.WriteLine(“IStorable not supported”); } ICompressible icDoc = doc as ICompressible; if ( icDoc != null ) { icDoc.Compress(); 184. Thực Thi Giao Diện. Ngôn Ngữ Lập Trình C# } else { Console.WriteLine(“Compressible not supported”); } ILoggedCompressible ilcDoc = doc as ILoggedCompressible; if ( ilcDoc != null ) { ilcDoc.LogSavedBytes(); ilcDoc.Compress(); // ilcDoc.Read(); // không thể gọi được } else { Console.WriteLine(“LoggedCompressible not supported”); } IStorableCompressible isc = doc as IStorableCompressible; if ( isc != null ) { isc.LogOriginalSize(); // IStorableCompressible isc.LogSavedBytes(); // ILoggedCompressible isc.Compress(); // ICompress isc.Read(); // IStorable } else { Console.WriteLine(“StorableCompressible not supported”); } IEncryptable ie = doc as IEncryptable; if ( ie != null ) { ie.Encrypt(); } else { Console.WriteLine(“Encryptable not supported”); } } 185. Thực Thi Giao Diện. Ngôn Ngữ Lập Trình C# } ----------------------------------------------------------------------------- Kết quả: Creating document with: Test Document Implementing the Read Method for IStorable Implementing Compress Implementing LogSavedBytes Implementing Compress Implementing LogOriginalSize Implementing LogSaveBytes Implementing Compress Implementing the Read Method for IStorable Implementing Encrypt ----------------------------------------------------------------------------- Ví dụ 8.2 bắt đầu bằn ...
Nội dung trích xuất từ tài liệu:
Giáo trình hình thành ứng dụng kỹ năng gán đối tượng cho một giao diện đối lập p2 . Ngôn Ngữ Lập Trình C# // bộ khởi tạo lớp Document lấy một tham số public Document( string s) { Console.WriteLine(“Creating document with: {0}”, s); } // thực thi giao diện IStorable public void Read() { Console.WriteLine(“Implementing the Read Method for IStorable”); } public void Write( object o) { Console.WriteLine(“Implementing the Write Method for IStorable”); } public int Status { get { return status; } set { status = value; } } // thực thi ICompressible public void Compress() { Console.WriteLine(“Implementing Compress”); } public void Decompress() { Console.WriteLine(“Implementing Decompress”); } // thực thi giao diện ILoggedCompressible public void LogSavedBytes() { Console.WriteLine(“Implementing LogSavedBytes”); 183. Thực Thi Giao Diện . Ngôn Ngữ Lập Trình C# } // thực thi giao diện IStorableCompressible public void LogOriginalSize() { Console.WriteLine(“Implementing LogOriginalSize”); } // thực thi giao diện public void Encrypt() { Console.WriteLine(“Implementing Encrypt”); } public void Decrypt() { Console.WriteLine(“Implementing Decrypt”); } // biến thành viên lưu dữ liệu cho thuộc tính private int status = 0; } public class Tester { public static void Main() { // tạo đối tượng document Document doc = new Document(“Test Document”); // gán đối tượng cho giao diện IStorable isDoc = doc as IStorable; if ( isDoc != null) { isDoc.Read(); } else { Console.WriteLine(“IStorable not supported”); } ICompressible icDoc = doc as ICompressible; if ( icDoc != null ) { icDoc.Compress(); 184. Thực Thi Giao Diện. Ngôn Ngữ Lập Trình C# } else { Console.WriteLine(“Compressible not supported”); } ILoggedCompressible ilcDoc = doc as ILoggedCompressible; if ( ilcDoc != null ) { ilcDoc.LogSavedBytes(); ilcDoc.Compress(); // ilcDoc.Read(); // không thể gọi được } else { Console.WriteLine(“LoggedCompressible not supported”); } IStorableCompressible isc = doc as IStorableCompressible; if ( isc != null ) { isc.LogOriginalSize(); // IStorableCompressible isc.LogSavedBytes(); // ILoggedCompressible isc.Compress(); // ICompress isc.Read(); // IStorable } else { Console.WriteLine(“StorableCompressible not supported”); } IEncryptable ie = doc as IEncryptable; if ( ie != null ) { ie.Encrypt(); } else { Console.WriteLine(“Encryptable not supported”); } } 185. Thực Thi Giao Diện. Ngôn Ngữ Lập Trình C# } ----------------------------------------------------------------------------- Kết quả: Creating document with: Test Document Implementing the Read Method for IStorable Implementing Compress Implementing LogSavedBytes Implementing Compress Implementing LogOriginalSize Implementing LogSaveBytes Implementing Compress Implementing the Read Method for IStorable Implementing Encrypt ----------------------------------------------------------------------------- Ví dụ 8.2 bắt đầu bằn ...
Tìm kiếm theo từ khóa liên quan:
giáo trình kế toán kỹ thuật kế toán thủ thuật kế toán phương pháp học kế toán bí quyết học kế toánGợi ý tài liệu liên quan:
-
10 trang 368 0 0
-
HUA Giáo trình nguyên lí kế toán - Chương 7
43 trang 154 0 0 -
quá trình hình thành quy trình hạch toán theo lương và các khoản trích theo lương p8
10 trang 61 0 0 -
Giáo trình Tổ chức hạch toán kế toán (Giáo trình đào tạo từ xa): Phần 1
66 trang 54 0 0 -
104 trang 50 0 0
-
CÁC VẤN ĐỀ CHÍNH TRONG BẢN BÁO CÁO TÀI CHÍNH
3 trang 41 0 0 -
Bài tập tổ chức công tác kế toán
4 trang 40 0 0 -
8 trang 39 0 0
-
Giáo trình hình thành ứng dụng điều tiết xuất nhập trong quá trình công nghiệp hóa p8
10 trang 34 0 0 -
Giáo trình kế toán tài chính doanh nghiệp_5
35 trang 29 0 0