Project design
- Dart course
- Beginner
- Lesson 112/116
- 6 min
Design the skeleton of the beginner final mini app.
Project design
In the beginner final we will build a small library app. The goal is to combine the beginner-level class, collections (List) and error handling (try/catch) in a real mini application.
In this lesson we design the skeleton: a Library class, a String name field and a void info() method. The next lessons add the book class, collection management and error catching. Each lesson's initial code includes the previous lesson's solution; so you grow the project step by step.
The class skeleton
A class skeleton has these parts: the class keyword, the class name, fields and a constructor in curly braces. The Library class will have a String name field and a Library(this.name) constructor. The constructor shares the class name and assigns parameters to fields.
To create an object from this class you write final lib = Library("City");. You access the field with lib.name. We can also add an info method to print the library information. On this skeleton we will add books and collections in the next lessons.
Practice Build the Library skeleton
Define a Library class with a String name field, a Library(this.name) constructor and a void info() method that prints "Library: $name". In main init with final lib = Library("City"); and call lib.info().
Starter code
void main() {
// define the Library class (outside main)
// create a Library and call info
}Sample solution
class Library {
String name;
Library(this.name);
void info() {
print("Library: $name");
}
}
void main() {
final lib = Library("City");
lib.info();
}Expected output
Library: City
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is the goal of this project?
- Combine class, collections and error handling Correct answer
- Only declare variables
- Only write loops
- Only print text
Explanation: the project combines three topics in a real app.
2 The class keyword
____ Library {
String name;
Library(this.name);
}
class Library {
String name;
Library(this.name);
}
Explanation: class starts the class definition.
3 Match the class parts
| Term | Meaning |
|---|---|
class |
starts the definition |
String name |
field |
Library(this.name) |
constructor |
void info() |
method |