Category Archive: Examples

Nov
29
2011

Factories / Pool Object Dart

With the current builders object factories are always asked a new object, the problem is that the programmer does not always want a new object, that gives us the advantage to pick up theobjects housed in the cache: There are several design patterns to do this correctly, but Dartmakes it easy with special constructs for factories. (Colloquially called constructors without tears).
 

The instance creation expressions are based on interfaces and minimizes the need fordependency injection.

Example of use of factory:

interface Person factory PersonFactory{
    Person(name);
    final name;
}
class PersonFactory{
   factory Person(name){
    if(name== null) return const Ghost();
    return new RealPerson(name);
   }
}
class RealPerson implements Person{
  RealPerson(this.name);
  final name;
}
class Ghost implements Person{
  const Ghost();
  get name() => "ghost";
}
main(){
  print(new Person("Pepita") is RealPerson);
  print(new Person(null) is Ghost);
}

Permanent link to this article: http://www.dartexperience.com/en/2011/11/29/factoriaspool-de-objetos-en-dart/

Nov
17
2011

Strings in Dart

This time we will make an example of String operations.

All the string methods here.

The example for this is commented in order to follow easily. You can run it through the button at the top the result will showed on the console at the bottom.

Read the rest of this entry »

Permanent link to this article: http://www.dartexperience.com/en/2011/11/17/strings-in-dart/

Nov
14
2011

Dart and HTML Elements. Part 3

This post is a continuation of our two previous articles, if you do not understand something, maybe you should consult they (Part 1, Part 2). It’s inspired on the Chris Buckett’s example.

We will create a simple form to collect name and surname and greet to our visitors. We will create the form dynamically using constructors. We will use an event to capture the button clicked event and we will show a text into a div for our greeting.

This is the structure of the example:

client/client.html – Page with reference to our script, nothing more.

Read the rest of this entry »

Permanent link to this article: http://www.dartexperience.com/en/2011/11/14/dart-and-html-elements-part-3/

Nov
10
2011

Getting started with Dart – Dart used in HTML

Dart is a new structured programming language for the browser. Like JavaScript, Dartapplications can be directly integrated into HTML pages.

Then show the correct syntax to be entered into our HTML in addition to some examples:

Dart MIME type

To <script> HTML tags (used to define the language to be used on the label), in our case we use’application / dart’.

As in javascript are two ways to insert our code:

Read the rest of this entry »

Permanent link to this article: http://www.dartexperience.com/en/2011/11/10/primeros-pasos-con-dart-%e2%80%93-incluyendo-dart-en-html/

Nov
04
2011

Getting Started with Dart and Eclipse Dart Editor – Run an example

Once we have our Dart Editor installed (for it is one of these links):

I will explain step by step how to run our first example.

We will do this in 3 steps:

1.- Open and run an example:

Initial screen of our Dart Editor:

To open the sample click on File> open … and choose a single element. “dart” of the project weloaded all the required libraries for this project.

This is achieved by

#library

To import the necessary libraries to run Dart, As you may have obserbar is used:

#import('dart:dom');

When we have the project loaded click on the following button to run the project and will open aweb browser to our example as simple as that:

 

And we have our example

As you can see it is quite easy to run our projects with Dart

Permanent link to this article: http://www.dartexperience.com/en/2011/11/04/primeros-pasos-con-dart-y-eclipse-dart-editor-ejecutar-un-ejemplo/