O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Classes

A class defines a set of properties and suitable operations. From a type-safe programming language point of view, a class is a structure to implement a user-defined type, such as our User class in the preceding example.

Preferably, a class should be an implementation of an Abstract Data Type (ADT) that hides the implementation details.

An implementation of an ADT as a class can be composed of two kinds of method:

  • Methods that return meaningful abstractions about the state of an instance
  • Transformational methods to move from a valid instance state to another valid state

To be able to hide implementation details and for the sake of abstraction, all the data within a class should be private to the class.

Let's improve the abstraction ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required