Chapter 3. Programming Objects the D Way

In this chapter, we're going to build upon the foundation established in the previous chapter by looking at D's user-defined types, its support for object-oriented programming, and some peripherally related features. By the end of the chapter, we'll be finished with the basics of D and ready for more advanced topics. Here's our checklist:

  • User-defined types: enumerations, unions, structs, and classes
  • Working with objects: protection attributes, constructors, and destructors
  • Contract programming: contracts and invariants
  • Error handling: exceptions and asserts
  • MovieMan: adding menus via user-defined types

User-defined types

This section shows how to define custom types using enum, union, struct, and class. The latter ...

Get Learning D now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.