Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sp4ce-cowboy committed Apr 16, 2024
1 parent 61eb76f commit 14e4961
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions TowerForge/TowerForge/Commons/Utilities/ObjectSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,15 @@ import Foundation

/// The ObjectSet utility class represents a compromise between reducing the cyclomatic
/// complexity of enums by replacing enums with dictionaries, and increasing code safety
/// by using enums to limit input values.
/// by using hashable wrapped types to limit input values.
///
/// Essentially, as opposed to having an enum that violates the open-closed principle when
/// new objects are to be added, a dictionary is used instead. However, instead of having Strings
/// as keys, a specially defined hashable enum (i.e. rawRepresentable is String) is used to ensure
/// that arbitrary values cannot be used.
/// as keys, a specially defined hashable wrapped type is used to ensure that arbitrary values
/// cannot be used as keys.
///
/// The typical use case is a static dictionary whose keys are of the same type as the aforementioned
/// enums. The value is a closure that takes in a certain set of arguments and outputs an object that
/// is needed. For example, is the fullStorableCreation below, the key is a TFStorableType which is an
/// enum that has "registered" storable types, such as case .killAchievement. The value corresponding to
/// this is a closure that takes in a UUID, a TFStorableType, a Double and outputs a KillAchievement.
/// The benefit of this approach is that manual switch-cases can be entirely elimated (thus OCP not violated),
/// by simply calling the appropriate closure with the required key, while still maintaining
/// runtime uniqueness without the type erasure that would occur if a generic Storable initializer were to
/// be called.
/// This pattern is also applied across other Factory classes in TowerForge, according to specific
/// needs.
class ObjectSet {

static let availableEventTypes: [TFEvent.Type] =
Expand Down

0 comments on commit 14e4961

Please sign in to comment.