In many languages, you can structure your code according to certain paradigms. Dart is an object-oriented programming language. In this video, we will learn how to write multiple classes and how to inherit from another class.
- Hello, and welcome to Section 3, Learning Object-Oriented Programming in Dart. In this section, we will learn the basics of object-oriented programming. What are the similarities in comparison to other programming languages? How you can use them into our Dart programming language. Also, we're going to take a look at classes and object how to create a library, using getters and setters. We will use it into our game at the end of this section. Now we'll move on to the first video of this section that deals with classes and objects in Dart.
We will learn how to create a class, and how we can create an instance of this class. We will also learn how to provide a field, and how to use a constructor. In object-oriented programming, there are classes and objects. A class is defined of how an object can look like. Classes have properties and methods. For example, a car has the properties like Speed, Name, Color, and the methods StepInto to step into a car, Drive to move a car, Start to start the engine of a car.
On the other hand, you have objects which are the instances of a class. In our example it can be the car that you own. A program is made up of classes and objects. These are the building blocks of object-oriented program. Let's take a look at this now, in practice. First of all, we need to create a class called Environment with the method called stumbleUpon.
So, this class resembles Environment, and within the environment, anything can happen. Now, let us create an instance of this Environment class. So, whenever we are moving within our world, we can ask our environment if there is something we stumble upon. We can create a new instance of a class by calling New and then the name of the class. Then, we call upon the stumbleUpon method of the instance myEnvironment.
In our case, it will return the same sentence every time. Later on, we can interact with the end user by this method. All methods and properties are, by default, public in Dart. If a variable name starts with an underscore, then it is private. Another important part of classes in an object-oriented programming language are fields. So, in our case, we can add the fields name.
Every class can have a constructor. In our case, we're going to add one parameter in the constructor. Namely... So, we can give the field "name" a value when we instantiate our object. We can do this, for example, with the word "wood." Now, let's see that in action. You will see that he types out "wood you stumbled upon something." In this video, we have looked at how to create classes and objects This video would have given you the knowledge on how to build classes, and make some instatiation of them.
In the next video, we will see how inheritance works.
Dart is a new open-source programming language for the web. It is a single language for both client and server that can be used to build large-scale web, server, and mobile applications. Stop solving new challenges with the same old tools—let Dart show you a whole new way! In this course, author Joris Hermans guides you into the wonderful world of web development with the dartlang programming language. By following along, you get a more mature sense of how to build a great application and see all the facets needed to reach that goal.
Learn the important language features of Dart, along with some advanced features such as mixins and null-aware operators. Later on, see how to use unit tests, work with browser APIs, and set up of a web server. Finally, take a look at Angular 2, a great front-end framework also built by Google.
This course provides you with everything you need to know to start or enhance your career in web development with Dart.
- Installing Dart
- Creating a basic web application with Dart
- Creating DOM interactions
- Creating classes and objects
- Implementing a library
- Using parameters, null-aware operators, and mixins
- Testing your code
- Setting up APIs
- Using Dart localStorage
- Working with AngularJS
- Troubleshooting Dart applications