Closed yHoonyK closed 4 years ago
It contains updating protocol for capability-agent. It is that about internal mandatory property.
Improve access control by NuguInterface
https://github.com/yHoonyK/nugu-ios/tree/feature/improve-nugu-client
public protocol ExtensionAgentProtocol:
CapabilityAgentable,
ContextInfoDelegate,
HandleDirectiveDelegate {
/// The object that acts as the delegate of extension-agent
var delegate: ExtensionAgentDelegate? { get set }
}
public protocol ExtensionAgentConcretable {
var messageSender: MessageSendable! { get set }
}
final public class ExtensionAgent: ExtensionAgentProtocol, ExtensionAgentConcretable {}
If we want to use it like that, the coordinating role must be involved by the NuguClient.Builder
.
like this,
public class NuguClient {
public let extensionAgent: ExtensionAgentProtocol?
init(extensionAgent: ExtensionAgentProtocol?,
...
) {
self.extensionAgent = extensionAgent
...
}
}
extension NuguClient {
public class Builder {
public lazy var extensionAgent: (ExtensionAgentProtocol & ExtensionAgentConcretable)? = ExtensionAgent()
public func build() -> NuguClient {
let client = NuguClient(...)
// coordinate for extension-agent
extensionAgent?.messageSender = client.networkManager
client.directiveSequencer.add(handleDirectiveDelegate: extensionAgent)
...
return client
}
}
}
Swift official answer for access-control protected
: https://developer.apple.com/swift/blog/?id=11
discussion(internal): https://github.com/orgs/nugu-developers/teams/nugu-sdk-ios-team/discussions/3
public protocol ExtensionAgentProtocol:
CapabilityAgentable,
ContextInfoDelegate,
HandleDirectiveDelegate {
init(messageSender: MessageSendable)
/// The object that acts as the delegate of extension-agent
var delegate: ExtensionAgentDelegate? { get set }
}
final public class ExtensionAgent: ExtensionAgentProtocol {
private let messageSender: MessageSendable
public init(messageSender: MessageSendable) {
self.messageSender = messageSender
}
}
let client: NuguClient = {
let builder = NuguClient.Builder()
return builder
.with(extensionAgent: ExtensionAgent(messageSender: builder.networkManager))
.build()
}()
I think @Minddol's suggestion is the best way.
Improve issue that NuguClient.Builder()
is always make all of capability-agent.
extension NuguClient.Builder {
enum DefaultType {
case .nothing // no has default capability-agent instance (only has `SystemAgent`)
case .basic // has basic capability-agent instances (`SystemAgent`, `ASRAgent`, `TTSAgent`, `TextAgent`..?)
case .complete // has all capability-agent instances
}
}
class NuguClient.Builder {
init(defaultType: DefaultType) {}
}
let client = NuguClient.Builder(defaultType: .basic).build()
Builder pattern with director. https://johngrib.github.io/wiki/builder-pattern/
I consider to change architecture to 'abstract factory pattern' for capability-agent.
Revert renaming capability-agents.
NuguClient.Builder()
is always make all of capability-agent.
NuguClient
conform to DI(Dependency injection) pattern and using 'constructor injection' type of DI.CapabilityAgentFactory
and MediaPlayerFactory
conform to 'Abstract Factory' pattern.Resolved by #147
It wasn't be completed.
Improve capability-agent protocol structure to PoP (Protocol Oriented Programming)
Resolved by #170
After that, we consider that NuguClient
change design-pattern to IoC container.
It will makes another github issue.
Overviews
Category
Summary
NuguClient.Builder()
is always make all of capability-agent. Some capability-agent may not be used. (likeLocationAgent
)Reference
Discussion(Internal): https://github.com/orgs/nugu-developers/teams/nugu-sdk/discussions/7