0

It is an abstract API upon which more domain specific APIs are based for querying URLs. Should the abstract version (which contains the networking functions, and the data structure) be written as a Class, Struct, or Protocol?

Brandon Bradley
  • 3,160
  • 4
  • 22
  • 39

1 Answers1

0

Given your requirements, it should be either a class, or a combination of a class and a protocol.

  • You cannot use protocol by itself, because it is incapable of holding data
  • Structs are a poor fit for anything abstract, because Swift structs are good for small types that have value semantic.

One approach that is good for data hiding is to expose a protocol, along with a method to obtain an instance of that protocol, but make the class implementing the protocol private to your implementation. This way the users would have to program to interface, because they have no access to the class itself.

Community
  • 1
  • 1
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523