Skip to content

Instantly share code, notes, and snippets.

@Chinecherem20199
Created May 16, 2022 12:43
Show Gist options
  • Save Chinecherem20199/f3f9179e389660736662cd871483f29a to your computer and use it in GitHub Desktop.
Save Chinecherem20199/f3f9179e389660736662cd871483f29a to your computer and use it in GitHub Desktop.
Class Fundamental in Dart
//use classes to define new type
//we are used to int, String, bool, List, Map, Set, Function
//classes - blueprint for objects
//object - container that holds some data (functionality in manipulate the data)
void main() {
var myHouse = House(nuOfWindows: 8, nuOfDoors: 4, typesOfWalls: 'Brick', typesOfRoof:'Tile');
// myHouse.nrOfDoors = 10;
//
// print(myHouse.nrOfDoors);
myHouse.printHouses();
}
//classess are created outside a main method
class House {
int nrOfWindows = 0;
int nrOfDoors = 0;
String typeOfWalls = '';
String typeOfRoof = '';
//create constructor
House(
{required int nuOfWindows,
required int nuOfDoors,
required String typesOfWalls,
required String typesOfRoof}) :
this.nrOfWindows = nuOfWindows,
this.nrOfDoors = nuOfDoors,
this.typeOfWalls = typesOfWalls,
this.typeOfRoof = typesOfRoof;
//This is a method or function
void printHouses() {
print('number of windows: ${this.nrOfWindows}');
print('number of doors : ${this.nrOfDoors}');
print('type of walls: ${this.typeOfWalls}');
print('type of roof: ${this.typeOfRoof}');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment