0%
Encapsulation, Inheritance, Polymorphism — Chapter 10

Chapter 10 — Encapsulation, Inheritance, Polymorphism

Part 1A — Learn Dart · Chapter 10 of 62 · 7 h

Chapter 10 — Encapsulation, Inheritance, Polymorphism

Level: intermediate Estimated time: 7 h Prerequisites: Chapter 09 — Constructors and Modeling What you will be able to do by the end: protect a class's data with private members and validated getters and setters, build a class hierarchy with extends and super, override methods with @override, and write polymorphic code that handles Player, Enemy, and Boss the same way.


10.0 — Chapter Objectives

By the end of this chapter, you will be able to:

  • name the three OOP pillars covered here;
  • explain what encapsulation is in your own words;
  • show concretely the danger of a public property that can be modified any which way;
  • declare a private member with the _ prefix;
  • explain that the scope of _ is the library (the file), not the class;
  • write a getter that exposes a read-only value;
  • write a setter that validates a value before accepting it;
  • write private helper methods for internal use;
  • build a fully encapsulated Player class, with lives always bounded between 0 and a maximum;
  • explain what inheritance is and what it is for;
  • use extends to create a subclass;
  • say precisely what is inherited and what is not;
  • call the parent constructor with super;
  • call a parent method with super.methode();
  • override an inherited method;
  • use the @override annotation correctly;
  • explain polymorphism using an example;
  • iterate over a List<Character> containing Player and Enemy objects;
  • use is and as to test and cast a type;
  • build the Character → Player / Enemy / Boss hierarchy;
  • recognize the situations where inheritance is a poor choice.

Comments

Comments are powered by GitHub Discussions

Sign in with GitHub to join the discussion

Link copied!