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. . | Bài giảng Phát triển phần mềm nguồn mở: Bài 4 - Nguyễn Hữu Thể 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 & Methods 4. Getter & 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 & Methods class Person { private $name; //public, protected private $age; public function show(){ echo $this->name . " is " . $this->age . " years old!"; } } 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 & 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->name; return name; } } public function setName($name){ public void setName(String name){ $this->name = $name; = name; } } public function getAge(){ public int getAge(){ return $this->age; return age; } } public function setAge($age){ public void setAge(int age){ $this->age = $age; = age; } } } } 7 class Person{ Ex: private $name; private $age; public function getName(){ return $this->name; } public function setName($name){ $this->name = $name; } public function getAge(){ return $this->age; } public function setAge($age){ $this->age = $age; } public function show(){ echo $this->name . " is " . $this->age . " years old!"; } $p = new Person(); } .

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