peri hoki perihoki clarustologistics rimashaop.com angelpaintingtools.co.in vrjanaenergies.com cara scatter hitam maxwin spesifikasi scatter emas mahjong rtp mahjong wins 3 medan pola malam pgsoft cairkan 813jt keberuntungan tukang parkir cek rtp mahjong ways lebaran kisah inspiratif kuli bangunan menang mahjong wins peluang profit rtp mahjong ways 2 naik sopir angkot jackpot 89 juta mahjong wins temuan scatter jumat mahjong ways keajaiban malam menghidupkan suasana menang dengan gaya strategi cerdas mahjong putaran ajaib mahjong wins tumbang bahagia raup untung dengan trik scatter mahjong scatter hitam mahjong ways mengantarkan kemenangan tak terduga fenomena scatter hitam saat jam sepi server kemenangan besar dari scatter hitam mahjong ways pekerja serabutan raih jackpot mengagumkan di mahjong ways potensi emas setiap spin mahjong ways waktu spin terbaik untuk scatter hitam tukang becak raih rejeki di mahjong
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 282
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_set_cookie_params(): Cannot change session cookie parameters when headers already sent
Filename: Session/Session.php
Line Number: 294
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 304
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 314
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 315
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 316
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 317
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 375
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: drivers/Session_files_driver.php
Line Number: 108
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_set_save_handler(): Cannot change save handler when headers already sent
Filename: Session/Session.php
Line Number: 110
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_start(): Cannot start session when headers already sent
Filename: Session/Session.php
Line Number: 143
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
Tạo quản lý nhân viên với TypeScript - Freetuts
TYPESCRIPT 2.X CĂN BẢN
CÁC CHỦ ĐỀ
BÀI MỚI NHẤT
Tạo quản lý nhân viên với TypeScript
Trong bài viết này, mình sẽ tạo lớp Employee
để quản lý thông tin cơ bản của nhân viên và sau đó tạo các lớp con như Manager
, Developer
, và Designer
kế thừa từ lớp Employee
. Mục tiêu của mình là hiểu cách sử dụng lớp và kế thừa trong TypeScript để quản lý thông tin nhân viên.
Quản lý nhân viên với TypeScript
Đầu tiên, mình sẽ định nghĩa lớp Employee
với các thuộc tính cơ bản như name
, age
, position
và các phương thức để quản lý thông tin nhân viên.
class Employee {
constructor(public name: string, public age: number, public position: string) {}
displayInfo(): void {
console.log(`Name: ${this.name}, Age: ${this.age}, Position: ${this.position}`);
}
}
// Lớp con Manager kế thừa từ lớp Employee
class Manager extends Employee {
constructor(name: string, age: number) {
super(name, age, "Manager");
}
}
// Lớp con Developer kế thừa từ lớp Employee
class Developer extends Employee {
constructor(name: string, age: number) {
super(name, age, "Developer");
}
}
// Lớp con Designer kế thừa từ lớp Employee
class Designer extends Employee {
constructor(name: string, age: number) {
super(name, age, "Designer");
}
}
// Sử dụng các lớp đã định nghĩa
const manager = new Manager("Alice", 35);
const developer = new Developer("Bob", 28);
const designer = new Designer("Eve", 30);
manager.displayInfo(); // Hiển thị thông tin của Manager
developer.displayInfo(); // Hiển thị thông tin của Developer
designer.displayInfo(); // Hiển thị thông tin của Designer
class Employee { ... }:
Định nghĩa lớp cơ bản Employee
với ba thuộc tính là name
, age
, position
và một phương thức displayInfo()
để hiển thị thông tin của nhân viên.
class Manager extends Employee { ... }:
Tạo lớp con Manager
kế thừa từ lớp Employee
, và gọi phương thức super()
để truyền thông tin vào cho lớp cha.
Tương tự, class Developer extends Employee { ... }
và class Designer extends Employee { ... }
tạo các lớp con Developer
và Designer
tương ứng.
Kết quả
Khi mình chạy đoạn mã trên, kết quả sẽ hiển thị thông tin của từng nhân viên tương ứng với chức vụ của họ.
Name: Alice, Age: 35, Position: Manager
Name: Bob, Age: 28, Position: Developer
Name: Eve, Age: 30, Position: Designer
Trong bài viết này, mình đã tạo ra các lớp Employee
và các lớp con kế thừa từ lớp Employee
để quản lý thông tin của các nhân viên với các chức vụ khác nhau. Việc sử dụng classes và inheritance trong TypeScript giúp tổ chức code một cách cấu trúc và dễ dàng mở rộng cho các tính năng và thuộc tính mới. Nếu có thắc mắc hoặc muốn mở rộng thêm, đừng ngần ngại đặt câu hỏi!
Bài giải
-------------------- ######## --------------------
Câu hỏi thường gặp liên quan:
Cùng chuyên mục: