...

/

Comparing With Structs

Comparing With Structs

Let’s briefly define classes and explore how classes are different from structs.

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 parts ...