From 14e49617df8c3ef737986ccff025738db1f7c059 Mon Sep 17 00:00:00 2001 From: Rubesh Date: Tue, 16 Apr 2024 22:08:22 +0800 Subject: [PATCH] Update documentation --- .../Commons/Utilities/ObjectSet.swift | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/TowerForge/TowerForge/Commons/Utilities/ObjectSet.swift b/TowerForge/TowerForge/Commons/Utilities/ObjectSet.swift index 530d5f51..88b1fb78 100644 --- a/TowerForge/TowerForge/Commons/Utilities/ObjectSet.swift +++ b/TowerForge/TowerForge/Commons/Utilities/ObjectSet.swift @@ -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] =