TypeScript là một ngôn ngữ mã nguồn mở miễn phí hiện đang được phát triển và bảo trì bởi Microsoft. Nó là superset của JavaScript, với các bổ sung các tuỳ chọn kiểu tĩnh và lớp trên cơ sở lập trình hướng đối tượng cho ngôn ngữ này. Vì TypeScript là tập cha của JavaScript nên bất kì chương trình JavaScript nào đã có cũng đều là chương trình TypeScript hợp lệ. nhưng hầu hết các trình duyệt chưa hỗ trợ nên cần được biên dịch ra JavaScript để có thể hoạt động. Có 4 tính chất của một ngôn ngữ lập trình hướng đối tượng là tính bao đóng (encapsulation), tính kế thừa(inheritance), tính đa hình(polymorphism), tính trừu tượng(Abstraction) và TypeScript hỗ trợ cả 4 tính chất này một cách rõ ràng và ngắn gọn
1. Tính trừu tượng (Abstraction)
Lớp trừu tượng là lớp mà từ đó các lớp khác có thể kế thừa được. Không giống như interface, lớp trừu tượng có thể chứa các thuộc tính cũng như các hàm thực thi(các phương thức abstract thì chỉ khai báo chứ không thực thi). Trong TypeScript cũng sự dụng từ khóa abstract để định nghĩa các lớp và phương thức trừu tượng. Chúng ta cùng xét ví dụ ở dưới đây:
abstract class Employee{
private name:string;
private age:number;
private qualification:string;
constructor(name:string, age:number, qualification:string){
this.name = name;
this.age = age;
this.qualification = qualification;
}
abstract applyTheJob():void // phương thức abstract không chứa hàm thực thi
abstract mailCheck():void
getNameAge(){
console.log(this.name + this.age)
}
getQualification(){
console.log(this.qualification)
}
}
private name:string;
private age:number;
private qualification:string;
constructor(name:string, age:number, qualification:string){
this.name = name;
this.age = age;
this.qualification = qualification;
}
abstract applyTheJob():void // phương thức abstract không chứa hàm thực thi
abstract mailCheck():void
getNameAge(){
console.log(this.name + this.age)
}
getQualification(){
console.log(this.qualification)
}
}
Kế thừa từ lớp trừu tượng: các class được kế thừa phải khai báo đầy đủ các phương thức abstract của class cha
Abstraction (tính trừu tượng) và encapsulation (tính bao đóng chúng ta sẽ tìm hiểu ngay sau đây) là hai đặc điểm có liên quan nhau trong lập trình hướng đối tượng. Trừu tượng cho phép tạo ra các thông tin không được hiển thị rõ ràng và đóng gói cho phép một người lập trình thể hiện tính trừu tượng ở mức độ mong muốn.
class _employee extends Employee{
constructor(name:string, age:number, qualification:string){
super(name, age, qualification);
}
applyTheJob(){
console.log('Applying for web developer position')
}
mailCheck(){
console.log('Confirm mail before the interview')
}
}
constructor(name:string, age:number, qualification:string){
super(name, age, qualification);
}
applyTheJob(){
console.log('Applying for web developer position')
}
mailCheck(){
console.log('Confirm mail before the interview')
}
}
2. Tính bao đóng (Encapsulation):
Tính bao đóng là tính chất không cho phép cho người dùng hay đối tượng thay đổi dự liệu thành viên của đối tượng nội tại. Chỉ có các hàm thành viên của đối tượng mới có quyền thay đổi trạng thái nội tại đó. Các đối tượng khác muốn thay đổi cần phải truyền một thông điệp cho đối tượng. Việc quyết định có thay đổi hay không vẫn do đối tượng nội tại quyết định
Tính đóng gói là không cho phép bên ngoài biết được bên trong đối tượng có những gì hay logic xử lí như thế nào, nếu muốn thay đổi bên trong đối tượng thi phải được sự chấp nhận của đối tượng đó thông qua các mức độ truy cập private, protected, public
Tính đóng gói là không cho phép bên ngoài biết được bên trong đối tượng có những gì hay logic xử lí như thế nào, nếu muốn thay đổi bên trong đối tượng thi phải được sự chấp nhận của đối tượng đó thông qua các mức độ truy cập private, protected, public
Sau đây là một ví dụ về tính bao đóng:
class Employee{
private name:string;
private age:number;
private qualification:string;
constructor(name:string, age:number, qualification:string){
this.name = name;
this.age = age;
this.qualification = qualification;
}
public getInfo(){
console.log(`
Name: ${this.name};
age: ${this.age};
Qualification: ${this.qualification}
`);
}
}
let _employee = new Employee('NVA',24,'bachelor');
class ScutiCompany{ public member:number; public name:string; constructor(name:string){ this.name = name; } static getInfoEmployee(){ return _employee.getInfo(); } } ScutiCompany.getInfoEmployee();
Các thuộc tính trong class Employee để ở trạng thái private và chỉ có thể được lấy ra từ phương thức public getInfo(), như vậy đối tượng _employee sẽ được đóng gói. Từ đó class company có thể lấy được thông tin đối tượng employee từ phương thức getInfo()
3. Tính kế thừa (Inheritance)
Nhằm tránh việc khai báo lặp lại các phương thức và thuộc tính, thêm vào đó là thuận tiện trong việc bảo trì và nâng cấp code dễ dàng hơn và giải pháp là tính kế thừa. Tính kế thừa là tính chất rất quan trọng trong lập trình hướng đối tượng. Có thể thể hiện tính kế thừa trong TypeScript một cách dễ dàng qua từ khóa extends :class Company{
protected name:string;
protected member:number;
constructor(name:string, numberMember:number){
this.name = name;
this.member = numberMember;
}
public getInformation(){
console.log(`
Welcome ${this.name} <br/>
We have ${this.member} member
`);
}
}
class ITcompany extends Company{
public makeWebsite(nameProject:string){
console.log('We are making' + nameProject)
}
public makeProduct(nameProject:string){
console.log(`We are developing ${nameProject} our own product `)
}
}
let Scuti = new ITcompany('Scuti',15);
Scuti.getInformation();
Scuti.makeWebsite('OutSourcing_projects');
Scuti.makeProduct('CookStar');
Có thể dễ
dàng nhận thấy class ITcompany thừa kế từ class Company thông qua từ khóa
extends, từ đó các phương thức và thuộc
tính protected hay public đều được thế hiện ở class ITcompany
4. Tính đa hình (Polymorphism)
Tính đa
hình trong lập trình hướng đối tượng là sự thay đổi hành vi của phương thức ở mỗi đối tượng khác nhau. Đi đôi với tính kế thừa ta có tính đa hình cũng rất dễ
để thể hiện trong TypeScript. Ta cùng xét ví dụ quen thuộc sau sẽ thấy rõ ràng nhất tính đa hình trong OOP:
const PI = 3.14;
class Shape{
constructor(name:string){}
protected Perimeter(){}
protected Acreage(){}
}
class Circle extends Shape{
private radius:number;
constructor(name:string,radius:number){
super(name);
this.radius = radius;
}
Perimeter(){
let perimeter = 2*PI*this.radius;
console.log('Perimeter is:' + perimeter);
}
Acreage(){
let acreage = PI*this.radius*this.radius;
console.log('Acreage is:' + acreage);
}
}
Bây giờ tiếp
tục tạo thêm một class Square kế thừa từ Shape
class Square extends Shape{
private length:number;
private width:number;
constructor(name:string, length:number, width:number){
super(name);
this.length = length;
this.width = width;
}
Perimeter(){
let perimeter = (this.length + this.width)*2;
console.log('perimeter is :' + perimeter);
}
Acreage(){
let acreage = this.length * this.width;
console.log('acreage is :' + acreage);
}
}
let circle = new Circle('hinh tron',6);
circle.Perimeter(); // Perimeter is:37.68
circle.Acreage(); // Acreage is:113.03999999999999
let square = new Square('hinh cn',8,9);
square.Perimeter(); // Perimeter is :34
square.Acreage(); // Acreage is :72
Nhận thấy
cùng là một phương thức tính chu vi và diện tích được kế thừa từ class Shape
nhưng với các đối tượng khác nhau, thuộc tính khác nhau thì thực thi khác nhau
Lời kết (conclusion)
TypeScript vẫn đang trong quá trình phát triển. Trong quá
trình nguyên cứu TypeScript, tôi chỉ thấy cái khó của nó nằm ở cú pháp mới lạ.
Còn về phần tính năng, khái niệm thì khá quen với các ngôn ngữ hướng đối tượng
khác như C# hay PHP
Ngoài ra hiện nay rất nhiều thư viện cũng như framework của JavaScipt đã chuyển sang sử dụng cú pháp của TypeScript nên đây sẽ là ngôn ngữ rất đáng để đầu tư trong tương lai
Ngoài ra hiện nay rất nhiều thư viện cũng như framework của JavaScipt đã chuyển sang sử dụng cú pháp của TypeScript nên đây sẽ là ngôn ngữ rất đáng để đầu tư trong tương lai
ReplyDeleteSome us know all relating to the compelling medium you present powerful steps on this blog and therefore strongly encourage
contribution from other ones on this subject while our own child is truly discovering a great deal.
Have fun with the remaining portion of the year.
Selenium training in bangalore
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training
Nice article,i really admire after reading this blog....
ReplyDeleteBest Aviation Academy in Chennai
Air Hostess Academy in Chennai
Airline Courses in Chennai
Ground Staff Training in Chennai
Airport Management Courses in Bangalore
Airport Management Courses in Chennai
Air Hostess Academy in Chennai
Air Hostess Course in Mumbai
Ground staff training in Bangalore
Best Aviation Academy in Chennai
Nice blog and valuable for all people. Thank you for posting this.
ReplyDeleteNode JS Training in Chennai
Node JS Course
Best IELTS Coaching in Chennai
learn Japanese in Chennai
Best Spoken English Class in Chennai
TOEFL Coaching Centres in Chennai
Node JS Training in OMR
Node JS Training in Tambaram
Great blog...! This blog contains useful information about this topic. Thank you for sharing this blog and can you do more updates & sharing like from this blog.
ReplyDeleteExcel Training in Chennai
Excel Course in Chennai
Tableau Training in Chennai
Linux Training in Chennai
Oracle Training in Chennai
Job Openings in Chennai
Oracle DBA Training in Chennai
Pega Training in Chennai
corporate training in chennai
Power BI Training in Chennai
Excel Training in Tambaram
This was an excellent post and very good information provided,Thanks for sharing.
ReplyDeletePython training in chennai
Python course in chennai
Python Training in OMR
DevOps training in anna nagar
PHP Course in chennai
Python Training in T.Nagar
Tally course in chennai
DOTNET training in chennai
Thanks for sharing informative article with us..
ReplyDeleteDOT NET Training in Chennai
asp .net training in chennai
DOT NET Training Institute in Chennai
.net course in chennai
dot net training in vadapalani
Html5 Training in Chennai
Spring Training in Chennai
Struts Training in Chennai
Wordpress Training in Chennai
SAS Training in Chennai
I am happy for sharing on this blog its awesome blog I really impressed. thanks for sharing.
ReplyDeleteStart your journey with In Software Training in Bangalore and get hands-on Experience with 100% Placement assistance from experts Trainers @eTechno Soft Solutions Located in BTM Layout Bangalore.
python course in coimbatore
ReplyDeletejava course in coimbatore
python training in coimbatore
java training in coimbatore
php course in coimbatore
php training in coimbatore
android course in coimbatore
android training in coimbatore
datascience course in coimbatore
datascience training in coimbatore
ethical hacking course in coimbatore
ethical hacking training in coimbatore
artificial intelligence course in coimbatore
artificial intelligence training in coimbatore
digital marketing course in coimbatore
digital marketing training in coimbatore
embedded system course in coimbatore
embedded system training in coimbatore
Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
ReplyDeleteSelenium Training in Electronic City
This excellent website definitely has all of the information I needed about this subject and didn’t know subject who to ask.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThere are many slots and slot machines. Withdrawing money is safe and fast. Also great with all of the valuable information you have Keep up the good work you are doing well.
ReplyDeletepython training in chennai
python online training in chennai
python training in bangalore
python training in hyderabad
python online training
python flask training
python flask online training
python training in coimbatore
Great, this article is quite awesome and I have bookmarked this page for my future reference.
ReplyDeleteweb designing training in chennai
web designing training in omr
digital marketing training in chennai
digital marketing training in omr
rpa training in chennai
rpa training in omr
tally training in chennai
tally training in omr
There have been 20 hours of service outrage, which is even said to effect Salesforce. Salesforce training in Hyderabad
ReplyDeleteReally wonderful and interesting blog, I enjoyed reading this post.
ReplyDeletewhat is seo content writing
german language to english
salesforce basics
star certification
free hacking books
tableau real time interview questions
content about this title and keep updating here...
ReplyDeleteInformatica Training in Bangalore
Informatica Training in Chennai
Informatica MDM Training in Chennai
Informatica Course in Chennai
Good job...! I really happy to visit your post and thank you for your sharing...
ReplyDeleteReact JS Training in Chennai
Blue Prism Training in Bangalore
Blue Prism Training in Chennai
Blue Prism Online Training
Blue Prism Online Course
This information is really awesome thanks for sharing most valuable information.
ReplyDeleteworkday software training
workday training online
With special privileges and services, UEFA BET offers opportunities for small capitalists. Together ufa with the best websites that collect the most games With a minimum deposit starting from just 100 baht, you are ready to enjoy the fun with a complete range of betting that is available within the website
ReplyDeleteufabet , our one another option We are a direct website, not through an agent, where customers can have great confidence without deception The best of online betting sites is that our Ufa will give you the best price
หาคุณกำลังหาเกมส์ออนไลน์ที่สามารถสร้างรายได้ให้กับคุณ เรามีเกมส์แนะนำ เกมยิงปลา รูปแบบใหม่เล่นง่ายบนมือถือ คาสิโนออนไลน์ บนคอม เล่นได้ทุกอุปกรณ์รองรับทุกเครื่องมือ มีให้เลือกเล่นหลายเกมส์ เล่นได้ทั่วโลกเพราะนี้คือเกมส์ออนไลน์แบบใหม่ เกมยิงปลา
อีกทั้งเรายังให้บริการ เกมสล็อต ยิงปลา แทงบอลออนไลน์ รองรับทุกการใช้งานในอุปกรณ์ต่าง ๆ HTML5 คอมพิวเตอร์ แท็บเล็ต สมาทโฟน คาสิโนออนไลน์ และมือถือทุกรุ่น เล่นได้ตลอด 24ชม. ไม่ต้อง Downloads เกมส์ให้ยุ่งยาก ด้วยระบบที่เสถียรที่สุดในประเทศไทย
Baccarat is money making plus it's spectacular availability. Optimal In your case it's being sold that you'll find pretty fascinating alternatives. And that is regarded as something that's very different And it's really a little something that's very happy to hit with Likely the most excellent, too, is a very positive choice. Furthermore, it's a really fascinating solution. It's the simplest way which could earn money. Superbly prepar The number of best-earning baccarat is the accessibility of making the most cash. Almost as possible is very ideal for you An alternative which may be guaranteed. To a wide variety of performance and supply And see outstanding benefits as well.บาคาร่า
ReplyDeleteufa
ufabet
แทงบอล
แทงบอล
แทงบอล
ได้โดยที่จะทำให้คุณนั้นสามารถสร้างกำไรจากการเล่นเกมส์เดิมพันออนไลน์ได้เราแนะนำเกมส์ชนิดนี้ให้คุณได้รู้จักก็เพราะว่าเชื่อว่าทุกคนนั้นจะต้องรู้วิธีการเล่นและวิธีการเอาชนะเกมม สล็อต าแทบทุกคนเพราะเราเคยเล่นกันมาตั้งแต่เด็กเด็กหาคุณได้เล่นเกมส์คาสิโนออนไลน์ที่คุณนั้นคุ้นเคยหรือจะเป็นสิ่งที่จะทำให้คุณสามารถที่จะได้กำไรจากการเล่นเกมได้มากกว่าที่คุณไปเล่นเกมส์คาสิโนออนไลน์ที่คุณนั้นไม่เคยเล่นมาก่อนและไม่คุ้นเคย เราจึงคิดว่าเกมส์ชนิดนี้เป็นเกมส์ที่น่าสนใจมากๆที่เราอยากจะมาแนะนำให้ทุกคนได้รู้จักและได้ใช้บริการ
ReplyDeleteVery nice post. Thank you for sharing with us.
ReplyDeleteTamil novels pdf download
Ramanichandran novels PDF
srikala novels PDF
Mallika manivannan novels PDF
muthulakshmi raghavan novels PDF
Infaa Alocious Novels PDF
N Seethalakshmi Novels PDF
Sashi Murali Tamil Novels PDF
Unlike hiring one individual bodyguard, when you hire UK Close Protection Services, you have added safety as we have a bodyguard servicescomplete team of experts meaning we have more resources if needed to ensure your safety. We can assess your requirements on a case-by-case level.
ReplyDeleteExcellent blog I visit this blog it's really awesome. The important thing is that in this blog content written clearly and understandable. The content of information is very informative.We are also providing the best services click on below links to visit our website.
ReplyDeleteOracle Fusion HCM Training
Workday Training
Okta Training
Palo Alto Training
Adobe Analytics Training
nice post. thanks for sharing........
ReplyDeleteCNC Programming Course in Coimbatore
best CNC Programming Course in Coimbatore
CNC Programming training Course in Coimbatore
CNC Programming training institute in Coimbatore
best CNC Programming training institute in Coimbatore
CNC Programming training in Coimbatore
best CNC Programming training in Coimbatore
CNC Programming training institute in Coimbatore with placement
CNC Programming Course fees in Coimbatore
CNC Programming Coching center in Coimbatore
I'm for the essential time frame here. I found this board and I in finding It in reality obliging and it helped me out abundance. I'm needing to expertise something already and sponsorship happening others, for instance, you helped me.
ReplyDeleteMicrosoft Office 2016 Product Key Generator
Good morning sweetie, you are my sunshine, the light of my life. I am glad to have in my life, I love you. Good morning my everything, I just want to let you.Good Morning Messages For GF
ReplyDelete