Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 41 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
41
Dung lượng
270,5 KB
Nội dung
Chapter : OOP Object-Oriented Programming Slide 2 11:40:41 AM 11:40:41 AM • Chiều thứ 6 ( 6/11/2009): thi lần 2 C# • H93 • 2h Object-Based Programming Slide 4 11:40:41 AM 11:40:41 AM Introduction • Procedural programming languages: action oriented (C, VB) – function • Object oriented (C#, C++, Java) – class (programmer-defined type) – Instance of class: object Slide 5 11:40:41 AM 11:40:41 AM Introduction ClassName - Properties + Methods Slide 6 11:40:41 AM 11:40:41 AM Introduction Console Propertes + Write(…) + Writeline(…) + ReadLine() + … System System.Window.Form Math - PI - E + Pow(…) + Sqrt(…) + Sin(…) +… MessageBox Propertes + Show(…) + … Form - Text - Name … + Close() + Hide() + Show() + … Object-Oriented Programming Slide 8 11:40:41 AM 11:40:41 AM Introduction • Object-Oriented Programming (OOP). • Abstraction • Encapsulation • Inheritance • Polymorphism Slide 9 11:40:41 AM 11:40:41 AM OOP Terminology-Abstraction • A model of an object that determines – Characteristics properties – Behaviors methods Abstraction Reality Object-Oriented Programming Object-Oriented Programming Slide 10 11:40:41 AM 11:40:41 AM OOP Terminology-Encapsulation • Combination of characteristics of an object along with its behaviors one “package” • Data hiding – Properties and procedures are hidden – Programmer controls “exposure” of properties and methods available to other objects – private Object-Oriented Programming Object-Oriented Programming [...]... one method with different argument lists Polymorphism is the ability to take on Polymorphism is the ability to take on many shapes or forms many shapes or forms Object-Oriented Programming Object-Oriented Programming Object-Based Programming Thiết kế lớp public class TenLop • Thêm class mới vào project: Project < Add { Class,… // khai báo các thuộc tính (property) … // khai báo các phương thức khởi tạo... is called the base, superclass, or parent • The inherited class is called the derived, subclass, or child • A derived class has an “is a” relationship with its base class Object-Oriented Programming Object-Oriented Programming OOP Terminology-Inheritance namespace OOP namespace OOP {{ public partial class frmOOP_Programing Form public partial class frmOOP_Programing ::Form {{ OOP Terminology-Inheritance . TenLop { // khai báo c c thu c tính (property) … // khai báo c c phương th c khởi tạo (constructor) … // khai báo c c phương th c truy c p thu c tính … // khai báo c c phương th c kh c } Slide 17 11:40:41. (tt) • Ví dụ CHinhCN - ChieuDai - ChieuRong - DienTich - ChuVi … C c thu c tính nên đư c cung c p chế độ an toàn dữ liệu nên đư c khai báo thu c tính truy c p là private (nguyên t c đóng gói) . AM Introduction • Procedural programming languages: action oriented (C, VB) – function • Object oriented (C# , C+ +, Java) – class (programmer-defined type) – Instance of class: object Slide