@Joanna_Carter What about this (based on your example in Abstract methods - #21 by Joanna_Carter):
protocol Command {
var permitted: Bool { get set }
var enabled: Bool { get set }
func doExecute() -> Bool
func doExecuteSuccess()
func doExecuteFailure()
func checkBeforeExecute() -> Bool
func checkAfterExecute() -> Bool
}
extension Command {
func execute() throws -> Bool {
guard permitted else {
fatalError("Not permitted")
}
guard enabled else {
fatalError("Disabled")
}
guard checkBeforeExecute() else {
return false
}
let success = doExecute()
if success {
doExecuteSuccess()
guard checkAfterExecute() else {
return false
}
} else {
doExecuteFailure()
}
return success
}
}
Here, the supertype Command
is a protocol. It requires both the "abstract" methods and the properties needed by the execute
method. This execute
method can already be provided by the protocol through an extension.
Is this more along the lines of what you need?
Basically, the idea here is to not use classes simply as a means to share code, since protocols can do that. Here, only leaf nodes need to be classes or structs.