Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; WP_MatchesMapRegex has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-includes/class-wp.php on line 632

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Translation_Entry has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-includes/pomo/entry.php on line 14

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; POMO_Reader has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-includes/pomo/streams.php on line 12

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; POMO_FileReader has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-includes/pomo/streams.php on line 120

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; POMO_StringReader has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-includes/pomo/streams.php on line 175

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; POMO_CachedFileReader has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-includes/pomo/streams.php on line 221

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; POMO_CachedIntFileReader has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-includes/pomo/streams.php on line 236

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; WP_Widget_Factory has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-includes/widgets.php on line 544

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzAdSense has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/easy-adsense-lite.php on line 38

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzAdsWidget has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/easy-adsense-lite.php on line 941

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzAdsSearch has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/easy-adsense-lite.php on line 1003

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzAdsLU has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/easy-adsense-lite.php on line 1078

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzBaseOption has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 22

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzCheckBox has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 174

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzRadioBox has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 199

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzSelect has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 250

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzMessage has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 294

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzHelpTag has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 313

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzHelpPopUp has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 328

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzTextArea has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 346

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzText has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 366

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzSubmit has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 385

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzColorPicker has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 409

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzOneTab has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 432

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; EzMiniTab has a deprecated constructor in /var/www/phpcoban.com/public_html/wp-content/plugins/easy-adsense-lite/EzOptions.php on line 476
Bài 13 - Abstract - Interface trong PHP - PHP Cơ Bản

Bài 13 – Abstract – Interface trong PHP

PHP Cơ Bản
Abstract – Interface (lớp trừu tượng & lớp giao diện).
Trước tiên mình xin nói đôi lời về tác dụng của việc sử dụng phương pháp lập trình hướng đối tượng (OOP) trong PHP cũng như các ngôn ngữ lập trình khác. Theo như chúng ta đã biết thì việc lập trình thuần túy sẽ làm các lập trình viên tốn rất nhiều thời gian và công sức để có thể bảo trì sản phẩm của mình. Và đó cũng chính là lý do OOP ra đời. Lập trình theo hướng đối tượng sẽ giúp chúng ta bảo trì sản phẩm của mình một cách rất đơn giản và hiệu quả.
Để không mất thời gian của các bạn mình sẽ đi vào phần chính của bài hôm nay. Đó là Abstract và Interface trong OOP.
1.Abstract class (Lớp trừu tượng)
Lớp trừu tượng là gì : Chúng ta có thể hiểu đơn giản nó như một lớp cha cho tất cả các lớp con có cùng bản chất kế thừa nó. Chú ý là mỗi lớp con chỉ có thể thừa kế từ một lớp cha và chúng ta cũng không thể tạo được các đối tượng trực tiếp từ lớp cha. Các lớp này sẽ chứa các phương thức trừu tượng, các lớp khác khi kế thừa sẽ phải định nghĩa các phương thức ấy.
Sau đây mình sẽ lấy ví dụ để các bạn có thể dễ hiểu :
Ví dụ 1:
vd1
2. Interface (lớp giao diện)
Lớp giao diện là gì: Lớp này được xem như một mặt nạ cho tất cả các lớp cùng cách thức hoạt động nhưng có thể khác nhau về bản chất. Từ đó lớp dẫn xuất có thể kế thừa từ nhiều lớp Interface để bổ sung đầy để cách thức hoạt động của mình(đây gọi là đa kế thừa). Chú ý các bạn không được định nghĩa các phương thức trong lớp interface.
Ví dụ: vd2

Ngoài ra bạn cũng có thể vừa kế thừa 1 lớp trừu tượng và sử dụng nhiều lớp giao diện.
Ví dụ:vd3

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">