import Foundation

extension MConnectingSocketTcpMethodType
{
    private static func factoryMethod(
        type:MConnectingSocketTcpMethodType) -> MConnectingSocketTcpMethodProtocol.Type
    {
        switch type
        {
        case MConnectingSocketTcpMethodType.showpin:
            
            return MConnectingSocketTcpMethodShowpin.self
            
        case MConnectingSocketTcpMethodType.register:
            
            return MConnectingSocketTcpMethodRegister.self
            
        case MConnectingSocketTcpMethodType.registerResult:
            
            return MConnectingSocketTcpMethodRegisterResult.self
            
        case MConnectingSocketTcpMethodType.registerCancel:
            
            return MConnectingSocketTcpMethodRegisterCancel.self
            
        case MConnectingSocketTcpMethodType.connect:
            
            return MConnectingSocketTcpMethodConnect.self
            
        case MConnectingSocketTcpMethodType.standby:
            
            return MConnectingSocketTcpMethodStandby.self
        }
    }
    
    //MARK: internal
    
    static func factoryMethod(
        name:String,
        received:String) -> MConnectingSocketTcpMethodProtocol?
    {
        guard
        
            let type:MConnectingSocketTcpMethodType = MConnectingSocketTcpMethodType(
                rawValue:name)
        
        else
        {
            return nil
        }
        
        let methodType:MConnectingSocketTcpMethodProtocol.Type = factoryMethod(
            type:type)
        let method:MConnectingSocketTcpMethodProtocol = methodType.init(
            received:received)
        
        return method
    }
}

import Foundation

extension MConnectingSocketTcpMethodType
{
    private static let kMethodMap:[
        MConnectingSocketTcpMethodType:
        MConnectingSocketTcpMethodProtocol.Type] = [
            MConnectingSocketTcpMethodType.showpin:
                MConnectingSocketTcpMethodShowpin.self,
            MConnectingSocketTcpMethodType.register:
                MConnectingSocketTcpMethodRegister.self,
            MConnectingSocketTcpMethodType.registerResult:
                MConnectingSocketTcpMethodRegisterResult.self,
            MConnectingSocketTcpMethodType.registerCancel:
                MConnectingSocketTcpMethodRegisterCancel.self,
            MConnectingSocketTcpMethodType.connect:
                MConnectingSocketTcpMethodConnect.self,
            MConnectingSocketTcpMethodType.standby:
                MConnectingSocketTcpMethodStandby.self]
    
    //MARK: internal
    
    static func factoryMethod(
        name:String,
        received:String) -> MConnectingSocketTcpMethodProtocol?
    {
        guard
        
            let type:MConnectingSocketTcpMethodType = MConnectingSocketTcpMethodType(
                rawValue:name),
            let methodType:MConnectingSocketTcpMethodProtocol.Type = kMethodMap[
                type]
        
        else
        {
            return nil
        }
        
        let method:MConnectingSocketTcpMethodProtocol = methodType.init(
            received:received)
        
        return method
    }
}

Replace switch with method map
Replace switch with method map
