SlideShare a Scribd company logo
1 of 34
ADVANCED DART
Google Developers Students Clubs
Addis Ababa Science and Technology University
C O N T E N T S
2
o Object-Oriented Programming
o Class and objects
o Constructor
o Encapsulation
o Inheritance
o Polymorphism
GDSC
o Asynchronous Programming
o Async and Await
o Future
o Exception Handling
o Try Catch
OOP IN DART
DART –CLASSES AND
OBJECTS
• Dart is an object-oriented programming language, so it supports the
concept of class, object …etc.
• In Dart, we can define classes and objects of our own .
• We use the class keyword to do so.
• Dart is support object-oriented programming features like classes and
interfaces.
5
• Class is the blueprint of objects and class is the collection of data members and data function means
which include these fields, getter and setter, and constructor and functions.
• Objects are the instance of the class and they are declared by using new keyword followed by the
class name .
Declaring class in Dart : Declaring object in Dart:
Syntax: Syntax:
class class_name {
// body of class
}
Var object_name = new class_name(
[arguments] );
• Class is the keyword use to initialize the
class.
• Class_name is the name of the class.
• Body of class consists of fields,
constructors, getter and setter methods,
etc.
• new is the keyword use to declare the instance of the class
• Object_name is the name of the object its naming is similar to
the variable name in dart
• class_name is the name of the class whose instance variable is
been created.
• Arguments are the input which are needed to be pass if we
are willing to call a constructor.
6
• After the object is created to access the fields we
use ( . ) operator for that purpose.
Output :
Welcome to Addis Ababa
CONSTRUCTOR IN
DART
• A constructor is a special method used to initialize an object
• It is called automatically when an object is created and it can be used to set the initial
values for the object’s properties
8
• The constructor’s name should be the same as the class name
• Constructor doesn’t have any return type.
• If you don’t define a constructor for class, then you need to set the value of the properties manually
Without Constructor
Person person = Person();
person.name = “John”;
Person.age = 30;
WithConstructor
Person person = Person( “ John “ , 30 ) ;
Syntac for declaration Constructor
Class ClassName {
// Constructor declaration : same as class name
ClassName() {
//body of the constructor
}
}
9
Example of Constructor Example of Single line Constructor
ENCAPSULATION IN
DART
• Encapsulation is one of the important concepts of oop.
• Encapsulation means hiding data within a library, preventing it from outside
factors.
• It helps you control your program and prevent it from becoming too
complicated.
11
• To Achieve Encapsulation we need to Declare the class properties as private by using underscore ( _ ) .
• Providing public getter and setter methods to access and update the value of private property.
• Getter and setter methods are used to access and update the value of private property.
• Getter methods are used to access the value of private property .
• Setter methods are used to update the value of private property
12
C O N C E P T O F I N H E R I TA N C E
 In Dart one class can inherit another class i.e dart can create a new class from an
existing class.
 We make use of extend keyword to inherit another class
 Parent Class – it is the class whose properties are inherited by the child class.
 Child Class – it is the class that inherits the properties of the other classes.
Output :
This is This is class A
• Child classes inherit all properties and methods except
constructors of the patent class.
• Like Java, Dart also doesn’t support multiple inheritance
15
What is Super in Dart
• Super is used to refer to the parent class.
• It is used to call the parent class’s properties
and methods.
MacBookPro display
MacBook display
Laptop display
Output :
POLYMORPHISM IN
DART
• Poly means many and morph means forms.
• Polymorphism is the ability of an object to take on many forms.
• As humans, we have the ability to take on many forms. We can be a
student, a teacher, a parent, a friend, and so on. Similarly, in object-oriented
programming, polymorphism is the ability of an object to take on many
forms.
17
Output
It runs on petrol.
It runs on electricity.
18
Task
1. Write a dart program to create a class Laptop with properties [ id , name , ram ] and
create 3 objects of it and print all details.
2. Write a dart program to create a class Animal with properties [ id, name , color ].
Create another class called Cat and extends it from Animal. Add new properties
sound in String . Create an object of a Cat and print all details.
ASYNCHRONOUS
PROGRAMMING
ASYNCHRONOUS
PROGRAMMI NG I N
DART
• Asynchronous Programming is a way of writing code that allows a program to do
multiple task at the same time.
• Time consuming operations like fetching data from the internet, writing to a database,
reading from a file, and downloading a file can be performed without blocking the
main thread fo execution
21
Synchronous Programming
• In Synchronous programming the program is executed line by line, one at a time.
• Synchronous operation means a task that needs to be solved before proceeding to the next one
void main() {
print("First Operation");
print("Second Operation");
print("Third Operation");
print("Last Operation");
}
• Let’s assume Second Operation takes 5 seconds to load
then Third Operation and Last Operation need to wait
for 3 seconds. To solve this issue you can use
asynchronous programming.
22
Asynchronous Programming
• In Asynchronous programming the program execution continues to the next line without waiting to
complete other work.
• It simply means, Don’t Wait
• It represents the task that doesn’t need to solve before proceeding to the next one.
void main() {
print("First Operation");
Future.delayed(Duration(seconds:5),()=>print('Second Operation'));
print("Third Operation");
print("Last Operation");
}
First Operation
Third Operation
Last Operation
Second Operation
Output
W H Y W E N E E D A S Y N C H R O N O U S ?
23
• To Fetch Data From internet,
• To write something to database,
• To execute a long-time consuming task,
• To read data from file,
• To download file etc.
FUTURE IN DART
• In dart, the Future represents a value or error that is not yet available,
• It is used to represent a potential value, or error, that will be available at soe time in
the future
• You can create a future in dart by using Future class.
24
25
How to use Future in dart
 you can use future in dart by using then() method
A S Y N C A N D AWA I T I N D A R T
26
• Async/await is a feature in dart that allows us to write asynchronous code that looks and behaves like
synchronous code, making it easier to read
• When a function is marked async, it signifies that it will carry out some work that could take some time and
will return a future object that wraps the result of that work
• The await keyword allows you to delay the execution of an async function until awaited Future has finished.
This enables us to create code that appears to be synchronous but is actually asynchronous.
 To define an Asynchronous function, add async before the function body
 The await keyword work only in the async function.
27
H A N D L I N G
E R R O R S
You can handle errors in the dart async
function by using try-catch .
28
29
Task
1. Write a program to print current time after 5 seconds using
Future.delayed()
2. Write a program in dart that uses Future class to perform multiple
asynchronous operations, wait for all of them to complete, and then
print the results.
EXCEPTION HANDLING
IN DART
• An exception is an error that occurs at runtime during program execution.
• When the exception occurs, the flow of the program is interrupted, and the
program terminates abnormally. There is a high chance of crashing or
terminating the program when an exception occurs. Therefore, to save your
program from crashing, you need to catch the exception.
30
T RY & C AT C H
I N D A R T
• Try – you can write the logical
code that creates exceptions in
the try block.
• Catch – when you are uncertain
about what kind of exception a
program produces, then a
catch block is used. It is written
with a try block to catch the
general exception
F I N A L LY I N
D A R T T RY
C AT C H
• The finally block is always
executed whether the
exceptions occur or not.
• It’s optional to include the final
block, but if it is included, it
should be after the try and
catch block is over.
T H R O W I N G
A N
E X C E P T I O N
• The throw keyword is used to
raise an exception explicitly
• A raised exception should be
handled to prevent the
program from exiting
unexpectedly .
THANK YOU
Google Developers Students Clubs
Addis Ababa Science and Technology University

More Related Content

Similar to advance-dart.pptx

Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application DevelopmentDhaval Kaneria
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptxVijalJain3
 
SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTnikshaikh786
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1Geophery sanga
 
Module 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptxModule 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptxGaneshRaghu4
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPTAjay Chimmani
 
Java Programming concept
Java Programming concept Java Programming concept
Java Programming concept Prakash Poudel
 
Csharp introduction
Csharp introductionCsharp introduction
Csharp introductionSireesh K
 
introduction to c #
introduction to c #introduction to c #
introduction to c #Sireesh K
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Vu Tran Lam
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsakreyi
 
Constructor destructor.ppt
Constructor destructor.pptConstructor destructor.ppt
Constructor destructor.pptKarthik Sekar
 
Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)MD Sulaiman
 

Similar to advance-dart.pptx (20)

Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application Development
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPT
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1
 
Module 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptxModule 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptx
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
 
Oop ppt
Oop pptOop ppt
Oop ppt
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
Java Programming concept
Java Programming concept Java Programming concept
Java Programming concept
 
Letest
LetestLetest
Letest
 
Csharp introduction
Csharp introductionCsharp introduction
Csharp introduction
 
introduction to c #
introduction to c #introduction to c #
introduction to c #
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
Java_notes.ppt
Java_notes.pptJava_notes.ppt
Java_notes.ppt
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
 
Constructor destructor.ppt
Constructor destructor.pptConstructor destructor.ppt
Constructor destructor.ppt
 
Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)
 
80410172053.pdf
80410172053.pdf80410172053.pdf
80410172053.pdf
 

Recently uploaded

Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Recently uploaded (20)

Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

advance-dart.pptx

  • 1. ADVANCED DART Google Developers Students Clubs Addis Ababa Science and Technology University
  • 2. C O N T E N T S 2 o Object-Oriented Programming o Class and objects o Constructor o Encapsulation o Inheritance o Polymorphism GDSC o Asynchronous Programming o Async and Await o Future o Exception Handling o Try Catch
  • 4. DART –CLASSES AND OBJECTS • Dart is an object-oriented programming language, so it supports the concept of class, object …etc. • In Dart, we can define classes and objects of our own . • We use the class keyword to do so. • Dart is support object-oriented programming features like classes and interfaces.
  • 5. 5 • Class is the blueprint of objects and class is the collection of data members and data function means which include these fields, getter and setter, and constructor and functions. • Objects are the instance of the class and they are declared by using new keyword followed by the class name . Declaring class in Dart : Declaring object in Dart: Syntax: Syntax: class class_name { // body of class } Var object_name = new class_name( [arguments] ); • Class is the keyword use to initialize the class. • Class_name is the name of the class. • Body of class consists of fields, constructors, getter and setter methods, etc. • new is the keyword use to declare the instance of the class • Object_name is the name of the object its naming is similar to the variable name in dart • class_name is the name of the class whose instance variable is been created. • Arguments are the input which are needed to be pass if we are willing to call a constructor.
  • 6. 6 • After the object is created to access the fields we use ( . ) operator for that purpose. Output : Welcome to Addis Ababa
  • 7. CONSTRUCTOR IN DART • A constructor is a special method used to initialize an object • It is called automatically when an object is created and it can be used to set the initial values for the object’s properties
  • 8. 8 • The constructor’s name should be the same as the class name • Constructor doesn’t have any return type. • If you don’t define a constructor for class, then you need to set the value of the properties manually Without Constructor Person person = Person(); person.name = “John”; Person.age = 30; WithConstructor Person person = Person( “ John “ , 30 ) ; Syntac for declaration Constructor Class ClassName { // Constructor declaration : same as class name ClassName() { //body of the constructor } }
  • 9. 9 Example of Constructor Example of Single line Constructor
  • 10. ENCAPSULATION IN DART • Encapsulation is one of the important concepts of oop. • Encapsulation means hiding data within a library, preventing it from outside factors. • It helps you control your program and prevent it from becoming too complicated.
  • 11. 11 • To Achieve Encapsulation we need to Declare the class properties as private by using underscore ( _ ) . • Providing public getter and setter methods to access and update the value of private property. • Getter and setter methods are used to access and update the value of private property. • Getter methods are used to access the value of private property . • Setter methods are used to update the value of private property
  • 12. 12
  • 13. C O N C E P T O F I N H E R I TA N C E  In Dart one class can inherit another class i.e dart can create a new class from an existing class.  We make use of extend keyword to inherit another class  Parent Class – it is the class whose properties are inherited by the child class.  Child Class – it is the class that inherits the properties of the other classes.
  • 14. Output : This is This is class A • Child classes inherit all properties and methods except constructors of the patent class. • Like Java, Dart also doesn’t support multiple inheritance
  • 15. 15 What is Super in Dart • Super is used to refer to the parent class. • It is used to call the parent class’s properties and methods. MacBookPro display MacBook display Laptop display Output :
  • 16. POLYMORPHISM IN DART • Poly means many and morph means forms. • Polymorphism is the ability of an object to take on many forms. • As humans, we have the ability to take on many forms. We can be a student, a teacher, a parent, a friend, and so on. Similarly, in object-oriented programming, polymorphism is the ability of an object to take on many forms.
  • 17. 17 Output It runs on petrol. It runs on electricity.
  • 18. 18 Task 1. Write a dart program to create a class Laptop with properties [ id , name , ram ] and create 3 objects of it and print all details. 2. Write a dart program to create a class Animal with properties [ id, name , color ]. Create another class called Cat and extends it from Animal. Add new properties sound in String . Create an object of a Cat and print all details.
  • 20. ASYNCHRONOUS PROGRAMMI NG I N DART • Asynchronous Programming is a way of writing code that allows a program to do multiple task at the same time. • Time consuming operations like fetching data from the internet, writing to a database, reading from a file, and downloading a file can be performed without blocking the main thread fo execution
  • 21. 21 Synchronous Programming • In Synchronous programming the program is executed line by line, one at a time. • Synchronous operation means a task that needs to be solved before proceeding to the next one void main() { print("First Operation"); print("Second Operation"); print("Third Operation"); print("Last Operation"); } • Let’s assume Second Operation takes 5 seconds to load then Third Operation and Last Operation need to wait for 3 seconds. To solve this issue you can use asynchronous programming.
  • 22. 22 Asynchronous Programming • In Asynchronous programming the program execution continues to the next line without waiting to complete other work. • It simply means, Don’t Wait • It represents the task that doesn’t need to solve before proceeding to the next one. void main() { print("First Operation"); Future.delayed(Duration(seconds:5),()=>print('Second Operation')); print("Third Operation"); print("Last Operation"); } First Operation Third Operation Last Operation Second Operation Output
  • 23. W H Y W E N E E D A S Y N C H R O N O U S ? 23 • To Fetch Data From internet, • To write something to database, • To execute a long-time consuming task, • To read data from file, • To download file etc.
  • 24. FUTURE IN DART • In dart, the Future represents a value or error that is not yet available, • It is used to represent a potential value, or error, that will be available at soe time in the future • You can create a future in dart by using Future class. 24
  • 25. 25 How to use Future in dart  you can use future in dart by using then() method
  • 26. A S Y N C A N D AWA I T I N D A R T 26 • Async/await is a feature in dart that allows us to write asynchronous code that looks and behaves like synchronous code, making it easier to read • When a function is marked async, it signifies that it will carry out some work that could take some time and will return a future object that wraps the result of that work • The await keyword allows you to delay the execution of an async function until awaited Future has finished. This enables us to create code that appears to be synchronous but is actually asynchronous.  To define an Asynchronous function, add async before the function body  The await keyword work only in the async function.
  • 27. 27
  • 28. H A N D L I N G E R R O R S You can handle errors in the dart async function by using try-catch . 28
  • 29. 29 Task 1. Write a program to print current time after 5 seconds using Future.delayed() 2. Write a program in dart that uses Future class to perform multiple asynchronous operations, wait for all of them to complete, and then print the results.
  • 30. EXCEPTION HANDLING IN DART • An exception is an error that occurs at runtime during program execution. • When the exception occurs, the flow of the program is interrupted, and the program terminates abnormally. There is a high chance of crashing or terminating the program when an exception occurs. Therefore, to save your program from crashing, you need to catch the exception. 30
  • 31. T RY & C AT C H I N D A R T • Try – you can write the logical code that creates exceptions in the try block. • Catch – when you are uncertain about what kind of exception a program produces, then a catch block is used. It is written with a try block to catch the general exception
  • 32. F I N A L LY I N D A R T T RY C AT C H • The finally block is always executed whether the exceptions occur or not. • It’s optional to include the final block, but if it is included, it should be after the try and catch block is over.
  • 33. T H R O W I N G A N E X C E P T I O N • The throw keyword is used to raise an exception explicitly • A raised exception should be handled to prevent the program from exiting unexpectedly .
  • 34. THANK YOU Google Developers Students Clubs Addis Ababa Science and Technology University