skip to content

Object-Oriented Features

Dart's object model: constructors from factory to primary, extends versus implements, mixins, class modifiers, extension types, equality and enums. Interviewers probe reuse without inheritance.

part ofDartoverview, primer and where to startread it →
on this pageshow

explore

questions

page 2 of 2

In Dart 3, what do `abstract interface class` and `abstract final class` declare, and which class modifier combinations does the compiler reject?

level: middleimportance: nice to knowfreq 25%

basics

~20 s

abstract interface class is Dart's pure interface: implementable elsewhere, never extended or constructed. abstract final class cannot be instantiated directly or subtyped outside its library, suiting static-only holders. Rejected: two of base/interface/final, sealed with any of them or abstract, and mixin with interface, final or sealed.

open as a page

In Dart 3.13, what do primary constructors and the concise new and factory constructor forms change, and what breaks when a package adopts language version 3.13?

level: seniorimportance: nice to knowfreq 20%

basics

~20 s

Dart 3.13 lets a class header declare fields and the main constructor, as in class Money(final int cents, final String currency);, and lets body constructors use new or factory without the class name. Adopting it makes final on ordinary parameters an error.

open as a page

In Dart, how can an enum implement interfaces and apply mixins, and how do you write generic code bounded by Enum?

level: seniorimportance: nice to knowfreq 22%

basics

~20 s

An enum can implement interfaces such as Comparable and apply mixins whose fields are final. Generic code uses T extends Enum to read index and name, but must receive the values list as an argument, since T.values does not compile.

open as a page

In Dart, what do `is`, `as` and pattern matches check when a value has an extension type, and why is that weaker than a wrapper class?

level: seniorimportance: nice to knowfreq 18%

basics

~20 s

Extension types are erased, so is, as, switch and if-case checks test the representation object's runtime type. UserId(7) is int and 7 is UserId are both true, and 7 as UserId skips any constructor validation — protection that exists only at compile time.

open as a page

In Dart, when does an overridden noSuchMethod actually run, and why can a class with one implement an interface without implementing its members?

level: seniorimportance: nice to knowfreq 18%

basics

~20 s

noSuchMethod runs when a call reaches a member the object lacks: via a dynamic receiver, or via a member its static type declares but its class leaves unimplemented while overriding noSuchMethod. Such classes get compiler-generated forwarders, so they compile without implementing the interface.

open as a page

showing 31–35 of 35