Bài giảng Phát triển phần mềm nguồn mở: Bài 4 - Nguyễn Hữu Thể

Bài 4 trình bày về lập trình hướng đối tượng "object oriented programming". Nội dung chính trong chương này gồm có: Class, visibility, properties & methods, Getter & getter, create objects, constructor, destructor, inheritance, abstract class, interfaces, autoloading classes, anonymous functions, closures, namespace. Mời các bạn cùng tham khảo. | PHÁT TRIỂN PHẦN MỀM NGUỒN MỞ OBJECT ORIENTED PROGRAMMING Nguyễn Hữu Thể Content 1. Class 2. Visibility 3. Properties amp Methods 4. Getter amp Setter 5. Create objects 6. Constructor 7. Destructor 8. Inheritance 9. Abstract class 10. Interfaces 11. Autoloading classes 12. Anonymous functions 13. Closures 14. Namespace 2 Class class ClassName Properties Methods 3 Visibility public private protected Three levels public private protected By default all class members are public. 4 Properties amp Methods class Person private name public protected private age public function show echo this- gt name . quot is quot . this- gt age . quot years old quot 5 Create objects Create a new instance of the class Using the new keyword new ClassName For example person new PerSon person2 new PerSon 6 Getter amp Setter PHP JAVA class Person class Person private name private String name private age private int age public function getName public String getName return this- gt name return name public function setName name public void setName String name this- gt name name name public function getAge public int getAge return this- gt age return age public function setAge age public void setAge int age this- gt age age age 7 class Person Ex private name private age public function getName return this- gt name public function setName name this- gt name name public function getAge return this- gt age public function setAge age this- gt age age public function show echo this- gt name . quot is quot . this- gt age . quot years old quot p new Person p- gt setName quot Nguyễn Văn A quot p- gt setAge 18 echo p- gt getName . quot is quot . p- gt getAge . quot years old. quot echo quot p- gt getName is p- gt getAge years old. quot p- gt show 8 _set method class SetName public function _set variable value echo variable echo quot My quot . variable . quot is quot . value . quot n quot obj new SetName obj- gt Name Tom obj- gt Name Jerry My Name is Tom My Name is Jerry 9

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU XEM NHIỀU
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
13    92    1    29-03-2024
Đã 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.