giving it a different name doesn't work. I'm loading resources on demand, some can change outside the app so need to be loaded on demand each time, others cannnot change outside the app (but more instances can be created) so can be cached. SOme of these lists are short and all objects will likely be used so shoudl be loaded all at once, other lists are long and only some objects will be used so need to just be loaded as need.
protocal loadedObjcts:class {
static func classSpecificType() -> String
static func loadObject(id:Iint) -> Self?
}
extension loadedObjcts {
static func loadObject(id: Int) -> Self? {
// code to load the object
}
}
protocal loadedStaticOjects: loadedObjects {
static var cachedObjects[Int:Self] {get set}
}
extension loadedStaticOjects {
static func loadObject(id: Int) ?Self {
if cachedObjects[id] == nil {
cachedObjects[id] = // code to load the object
}
return cachedObjects[id]
}
}
protocal preloadedStaicOjects: loadedStaticObjects {
static func loadObject(id:int) {
if cachedObjects.size == 0 {
// code to preload them all
}
// need to do the loadStaticObjects logic above to catch potential new cases
}
}
I also have a class hierarchy, each of the final classes implement the appropriate protocol and get the desired behavor. Clients just treat them all as implementing the loadedObjects protocol. They really don't need to know or care if they implement somethign different.
I can change the body fo the first two protocols so that they call a method that's only defined in the extension. The problem is I can't set a requirement where that method is only called by the loadObjects method and callign it otherwise breaks everything.
Waht I really need to be able to do is
let object = super.loadObject[id]
or somethign equivalent without exposing new methods that shouldn't be ever called by anythign other than a loadObject method.