Comparing With Structs
Understand the key distinctions between classes and structs in the D programming language. Learn how classes introduce object-oriented principles such as inheritance and polymorphism, behave as reference types, allow null values, and require special handling for comparison. This lesson prepares you to effectively use classes alongside structs in your D programming projects.
We'll cover the following...
Classes
Similar to structs, classes are features for defining new types. By this definition, classes are user defined types. Different from structs, classes provide the object oriented programming (OOP) paradigm in D. The major aspects of OOP are the following:
-
Encapsulation: Controlling access to members (Encapsulation is available for structs as well but it has not been mentioned until this chapter.)
-
Inheritance: Acquiring members of another type
-
Polymorphism: Being able to use a more special type in place of a more general type
Encapsulation is achieved by protection attributes, which you will see in a later chapter. Inheritance is for acquiring implementations of other types. Polymorphism is for abstracting ...