0
class X: Interface1, Delegate1, Delegate2 {
    var sharedVariable = true
    .... very long code comes here, that implements the delegates ...
}

How can I now break down this long class? I was thinking of using extensions, something like

extension X: Delegate1 {
    // .. some code here, uses sharedVariable
}

extension X:Delegate2 {
    // and some here, also uses sharedVariable
}

The problem with this approach is, that since both extensions use the sharedVariable, there is not much use breaking it down to extensions... Or is it? What else can I do with it?

Novellizator
  • 13,633
  • 9
  • 43
  • 65

1 Answers1

0

It depends on how the rest of your code is structured. One good reason to break the code into extensions is to provide each extension in the appropriate scope and/or context. In the extreme, one could implement the types as just data and provide all functions and computed properties as extensions based on the point of view needed in various contexts and scopes.

Tom Pelaia
  • 1,275
  • 10
  • 9