[go: up one dir, main page]

0% found this document useful (0 votes)
8 views1 page

Oop Dart

The document discusses how to achieve encapsulation in classes by declaring properties as private, providing public getter and setter methods, and using underscores for private properties. It also mentions read-only properties, getter and setter methods, inheritance, and named constructors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Oop Dart

The document discusses how to achieve encapsulation in classes by declaring properties as private, providing public getter and setter methods, and using underscores for private properties. It also mentions read-only properties, getter and setter methods, inheritance, and named constructors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Encapsulation can be achieved by:

Declaring the class properties as private by using underscore(_).

Providing public getter and setter methods to access and update the value of
private property.

-underscore_ mark for class property is LIBRARY PRIVATE


-read-only properties. You can do that by adding the final keyword before the
properties declaration

- Create Getter and Setter Methods?


+ String _model;
int _year;

// Getter method
String get model => _model;

// Setter method
set model(String model) => _model = model;

// Getter method
int get year => _year;

// Setter method
set year(int year) => _year = year;
}

- inheritance: 3. Named Constructor: As you can’t define multiple constructors with


the same name, this type of constructor is the solution to the problem. They allow
the user to make multiple constructors with a different name.

class_name.constructor_name ( parameters ){
// Body of Constructor
}

You might also like