Chapter 4. Modeling Web Applications with Model Concepts and Dartlero

Up until now, the apps we discussed were quite simple; there was no real need to design a model. However, when developing more complex (web) applications, a good model to start from will lay a more stable foundation for the code. In this chapter we will build a project from scratch, designing its model graphically, and start implementing it with a framework. The good thing is that we will use tools developed in Dart to do this. Because most of the projects we will develop are hosted on GitHub, we start by looking at how Git and GitHub work. We will cover the following topics:

  • A short introduction to Git and GitHub
  • What a model is and why we need it in programming
  • Model concepts – a graphical design tool for our models
  • Dartlero – a simple domain model framework
  • The categories and links model

A short introduction to Git and GitHub

Git is an open source software tool that allows groups of people to work together harmoniously on the same code project at the same time. So, it's a distributed version control system. The projects are published in the cloud, for example, in the GitHub repository https://github.com/ (there are other websites that accept Git projects, for example, Bitbucket at https://bitbucket.org/). Git maintains local copies of these projects on your computer(s). For this to work, the Git tool must be installed locally as well. To get started, create an account on the GitHub website or sign in if you already have one. Go to the site https://help.github.com/articles/set-up-git and click on the Download and install the latest version of Git link. If necessary, choose your OS and then let the wizard install Git on your machine with the default options. The code from this book resides in the following GitHub repository: https://github.com/Ivo-Balbaert/learning_dart. To create a local copy of the code examples:

  1. Make a folder where you store your Git downloads (for example, /home/git or d:git)
  2. Start the Git Bash command-line tool and go to that folder:
    cd git
    
  3. Clone the remote repository into your local repository by using the following command:
    git clone git://github.com/Ivo-Balbaert/learning_dart.git
    

A subfolder learning_dart is created and then all files are copied in it locally. Afterwards, if you want to get the latest changes from the remote repository, go to the local directory and use the following command:

git pull

Creating a repository on GitHub and a local version

This is easy; just follow the steps given here:

  1. Sign in into GitHub, click on the New Repository button, and fill in a repository name, say dart_projects. Then click on the Create Repository button (we follow the Dart style guidelines here and name it as a directory: lowercase_with_underscores). Now, your remote repository is created with the URL https://github.com/your_name/dart_projects.git.
  2. Create a folder for your local version of this repository, say git/dart_projects. Start Git bash and go to that folder with cd.
  3. Initialize an empty Git repository with the following command:
    git init
    
  4. Every project needs a readme file; so create an empty text file README.md in a simple text editor, and put some useful information in it with Dart Editor (or your favorite text-editor).
  5. We add this file to our local repository with the command:
    git add README.md.
    

    In general, the git add command will put all that is inside the directory into a waiting room (called a staging area or index). The git status command will show these new changes that are yet to be committed to your project. At this time, you make these changes permanent by committing our project with the following command:

    git commit -m 'created first version'
    

    Here, -m provides a message. You can also provide a text file called gitignore to contain files (or patterns of files) that are not to be included in the version control system.

  6. To push your local changes to your remote GitHub repository, use the following commands:
    git remote add origin https://github.com/your_name /dart_projects.git 
    

    and

    git push –u origin master
    

    (You will be asked to authenticate with your GitHub username and password).

  7. The next time you work on your project and want to store the changes in the repository (local and on GitHub), you can simply use the following command:
    git add .
    git commit -m 'verb something'
    git push 
    
  8. If you deleted a file, just use git rm filename before commit. You can also indicate a version of your project by giving it a tag, for example, s00:
    git tag -a s00 -m 'spiral 00' 
    
  9. To push these tags to the remote repository, use the following command:
    git push --tags
    

Collaborating on a GitHub project

If you want to invite someone else to join your project in order to make changes, select the repository of your project, use the Settings menu, and then select the Collaborators option. Add that person by using his or her GitHub name. If you are not alone on your project, you should always start your working session with the git pull command to get the latest changes and to avoid conflicts. Watch the videos at this link to get a good introduction to Git: http://git-scm.com/videos. Also, the basic concepts are explained in this course: https://www.codeschool.com/courses/try-git.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.118.229